package hotel.meituan.oversea.biz.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import hotel.base.oversea.constant.*;
import hotel.base.oversea.constant.enums.CommonEnums;
import hotel.base.oversea.constant.enums.MessageEnums;
import hotel.base.oversea.constant.enums.MtGoodsEnums;
import hotel.base.oversea.constant.enums.MtHotelEnums;
import hotel.base.oversea.constant.quartz.UrlMtEnums;
import hotel.base.oversea.dto.meituan.*;
import hotel.base.oversea.dto.switchs.SwitchCreateRoomDto;
import hotel.base.oversea.service.impl.BaseServiceImpl;
import hotel.base.oversea.utils.*;
import hotel.base.oversea.vo.meituan.request.goods.*;
import hotel.base.oversea.vo.meituan.request.room.MtHotelRealRoomVo;
import hotel.base.oversea.vo.meituan.response.goods.*;
import hotel.meituan.oversea.api.entity.*;
import hotel.meituan.oversea.api.enums.UrlInnerEnums;
import hotel.meituan.oversea.api.vo.switchs.ModifyPriceVo;
import hotel.meituan.oversea.api.vo.up.response.goods.MtHotelGoodsCallbackVo;
import hotel.meituan.oversea.api.vo.up.response.hotel.MtHotelDetailVo;
import hotel.meituan.oversea.biz.config.service.RedisService;
import hotel.meituan.oversea.biz.mapper.*;
import hotel.meituan.oversea.biz.service.MtHotelGoodsService;
import hotel.meituan.oversea.biz.service.MtHotelRoomNameService;
import hotel.meituan.oversea.biz.service.MtHotelService;
import hotel.meituan.oversea.biz.task.MeituanSaveApiLogTask;
import hotel.meituan.oversea.biz.utils.MtUtils;
import hotel.meituan.oversea.biz.utils.RestTemplateUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.web.client.RestTemplate;
import tk.mybatis.mapper.entity.Example;

import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.TimeUnit;

@Slf4j
@Service
public class MtHotelGoodsServiceImpl extends BaseServiceImpl implements MtHotelGoodsService {
    @Autowired
    private MtHotelGoodsMapper mtHotelGoodsMapper;

    @Autowired
    private MtHotelRoomNameService mtHotelRoomNameService;

    @Autowired
    private MtHotelActiveInfoMapper mtHotelActiveInfoMapper;
    @Autowired
    private MtHotelGoodsUpDownLogMapper mtHotelGoodsUpDownLogMapper;
    @Autowired
    private MtHotelGoodsPriceDaysMapper mtHotelGoodsPriceDaysMapper;
    @Autowired
    private MtHotelGoodsPriceDaysErrorMapper mtHotelGoodsPriceDaysErrorMapper;
    @Autowired
    private MtHotelRoomMapper mtHotelRoomMapper;
    @Autowired
    private MtHotelGoodsBreakfastMapper mtHotelGoodsBreakfastMapper;
    @Autowired
    private MtHotelGoodsBookRuleMapper mtHotelGoodsBookRuleMapper;
    @Autowired
    private MtHotelGoodsCancelRuleMapper mtHotelGoodsCancelRuleMapper;
    @Autowired
    private MtHotelGoodsInvoiceMapper mtHotelGoodsInvoiceMapper;
    @Autowired
    private MtHotelGoodsInventoryMapper mtHotelGoodsInventoryMapper;
    @Autowired
    private MtHotelGoodsInventoryLogMapper mtHotelGoodsInventoryLogMapper;
    @Autowired
    private MtHotelGoodsStatusMapper mtHotelGoodsStatusMapper;
    @Autowired
    private MtHotelGoodsPriceMapper mtHotelGoodsPriceMapper;
    @Autowired
    private MtHotelGoodsPriceLibraryMapper mtHotelGoodsPriceLibraryMapper;
    @Autowired
    private MtHotelGoodsPriceChangeLogMapper mtHotelGoodsPriceChangeLogMapper;
    @Autowired
    private MtHotelGoodsStatusChangeLogMapper mtHotelGoodsStatusChangeLogMapper;
    @Autowired
    private MtHotelService mtHotelService;
    @Autowired
    private RedisService redisService;

    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    MeituanSaveApiLogTask meituanSaveApiLogTask;

    //公共参数
    private  String version = MeituanConstants.VERSION;//版本号
    private  int partnerId = MeituanConstants.BUSINESS_ID;//平台分配给第三方渠道的分销业务ID
    private  String accesskey = MeituanConstants.ACCESS_KEY;//平台分配给第三方渠道的安全凭证公钥
    private String apiUrl = MeituanConstants.URL;//请求接口地址
    @Override
    public Result<Object> apiGoodsRp(String source,List<Long> hotelIds, String checkinDate, String checkoutDate, int goodsType) {
        //业务参数
        String data = "";
        Map<String,Object> dataMap = new HashMap<>();
        dataMap.put("hotelIds",hotelIds);
        dataMap.put("checkinDate",checkinDate);
        dataMap.put("checkoutDate",checkoutDate);
        dataMap.put("goodsType",goodsType);
        data = JSON.toJSONString(dataMap);
        //发起请求
        String response = MtUtils.createParamsPost(data, MtHotelEnums.apiMethodEnum.METHOD_HOTEL_GOODS.getMethod(),meituanSaveApiLogTask);
        return new Result<>(response,CommonConstants.SUCCESS);
    }
    /**
     * 根据入住时间和离店时间 查询产品数据
     * 多家酒店，最多查询10家；每家酒店可能存在多个产品；
     * @desc 保存：1、产品信息   2、关联的产品早餐信息
     */
    @Override
    public Result<Object> getMtHotelGoods(String source,List<Long> hotelIds, String checkinDate, String checkoutDate, int goodsType) {
        //业务参数
        String data = "";
        Map<String,Object> dataMap = new HashMap<>();
        dataMap.put("hotelIds",hotelIds);
        dataMap.put("checkinDate",checkinDate);
        dataMap.put("checkoutDate",checkoutDate);
        dataMap.put("goodsType",goodsType);
        data = JSON.toJSONString(dataMap);
        //发起请求
        String response = MtUtils.createParamsPost(data, MtHotelEnums.apiMethodEnum.METHOD_HOTEL_GOODS.getMethod(),meituanSaveApiLogTask);
        //处理响应数据
        JSONObject responseJson = JSON.parseObject(response);
        if("0".equals(String.valueOf(responseJson.get("code")))) {
            //上游返回code=0，不管result内容是不是为空，都不能返回为异常，算正常
            String result = responseJson.getString("result");
            if (null != result) {
                MtHotelGoodsVo mtHotelGoodsVo = null;
                try{
                    mtHotelGoodsVo = JSON.parseObject(result,MtHotelGoodsVo.class);
                }catch (Exception e){
                    log.error("//////////////////产品信息解析对象异常："+ JSON.toJSONString(response));
                    log.error(e.getMessage(),e);
                    return new Result<>("parse error",CommonConstants.REQUEST_ERROR);
                }
                if(null != mtHotelGoodsVo && null != mtHotelGoodsVo.getHotelGoods() && mtHotelGoodsVo.getHotelGoods().size()>0){
                    return new Result<>(mtHotelGoodsVo);
                }else{
                    return new Result<>();
                }
            }else{
                log.info("////////////////MTAPIERROR///////////////////酒店产品列表接口数据异常 result is null hotelIds={}",GsonUtils.GsonString(hotelIds));
                return new Result<>(response,CommonConstants.SUCCESS);
            }
        }else{
            return new Result<>(responseJson.getString("message"), CommonConstants.REQUEST_ERROR);
        }
    }

    /**
     * 查询产品接口，供下游调用，且返回真实的房型id，并构建返回数据(飞猪和携程返回数据不同)
     * @param source
     * @param manyHotelGoodsVos
     * @return
     */
    @Override
    public Result<Object> buildGoodsDataNotSave(List<Long> hotelIds,String source,MtHotelGoodsVo manyHotelGoodsVos){
        Map<Long,MtHotelDetailVo> hotelsDetailsMap = mtHotelRoomNameService.returnHotelDetailsMap(hotelIds);
        if(null == hotelsDetailsMap){
            hotelsDetailsMap = new HashMap<>();
        }
        //后期 酒店详情和物理房型从缓存拿
        Result manyHotelsRoomInfosResult = mtHotelRoomNameService.getMtHotelRoom(hotelIds);
        Map<Long,List<MtHotelRealRoomVo>> oneHotelRoomInfosDataArray = (Map<Long,List<MtHotelRealRoomVo>>)manyHotelsRoomInfosResult.getData();
        if(null == oneHotelRoomInfosDataArray){
            oneHotelRoomInfosDataArray = new HashMap<>();
        }

        if(null != manyHotelGoodsVos && hotelsDetailsMap.size()>0){
            //业务处理，保存数据
            List<MtHotelGoodsChildInfoVo> hotelsDataGoodsData = manyHotelGoodsVos.getHotelGoods();
            Map<String, List<MtHotelGoodsDto>> roomAboutgoodsDtosMap = new HashMap<>();
            List<MtHotelGoodsDataGroupRoomDto> mtHotelGoodsListDtoArray = new ArrayList<>();

            if(null != hotelsDataGoodsData && hotelsDataGoodsData.size()>0){//多个酒店则数组大于1
                Map<String,List<MtHotelGoodsBreakfastVo>> putRedisBreakfastData = new HashMap<>();
                for(MtHotelGoodsChildInfoVo oneHotelGoodsVo:hotelsDataGoodsData){
                    //遍历酒店产品信息
                    Integer hotelId = oneHotelGoodsVo.getHotelId();
                    if(null == hotelsDetailsMap.get(Long.valueOf(hotelId))){
                        continue;
                    }
                    MtHotelDetailVo mtHotelDetailVo = hotelsDetailsMap.get(Long.valueOf(hotelId));

                    List<MtHotelRealRoomVo> oneHotelRooms = null;
                    if(null != oneHotelRoomInfosDataArray.get(Long.valueOf(hotelId))){
                        oneHotelRooms = oneHotelRoomInfosDataArray.get(Long.valueOf(hotelId));
                    }

                    List<MtHotelGoodsBaseInfoVo> goods = oneHotelGoodsVo.getGoods();
                    if(null != goods && goods.size()>0){
                        //多家酒店，最多查询10家；每家酒店可能存在多个产品；
                        for (int i = 0; i <goods.size(); i++) {
                            MtHotelGoodsBaseInfoVo goodsBaseInfoVo = goods.get(i);
                            List<MtHotelGoodsBreakfast> breakfastEntityList = new ArrayList<>();
                            List<MtHotelGoodsBookRule> bookRuleEntityList = new ArrayList<>();
                            List<MtHotelGoodsCancelRule> cancelRuleEntityList = new ArrayList<>();
                            //遍历 一家酒店 - 所有产品
                            MtHotelGoods goodsEntity = new MtHotelGoods();
                            goodsEntity.setId(String.valueOf(UUID.randomUUID()));
                            goodsEntity.setMtHotelId(String.valueOf(hotelId));
                            goodsEntity.setMtGoodsId(goodsBaseInfoVo.getGoodsId());
                            goodsEntity.setMtGoodsName(goodsBaseInfoVo.getGoodsName());
                            List<MtHotelGoodsBaseRoomVo> goodsBaseRoom = goodsBaseInfoVo.getRoomInfoList();

                            if(null != goodsBaseRoom && goodsBaseRoom.size()>0){
                                /*if(goodsBaseRoom.size()>1){
                                    //上游标识每个产品只对应一个房间信息,但返回的是list，特殊处理
                                    log.error("////////////////MTAPIERROR///////////////////酒店产品列表接口数据异常 goodsBaseRoom size >1");
                                    //return new Result<>("goodsBaseRoom error overstep", CommonConstants.PARSE_ERROR);
                                }else{

                                }*/
                                goodsEntity.setMtCityId(goodsBaseRoom.get(0).getCityId());
                                goodsEntity.setMtRoomName(goodsBaseRoom.get(0).getRoomName());
                                goodsEntity.setMtFalseRoomId(goodsBaseRoom.get(0).getRoomId());//接口的roomId为假的房型id，先保存预留

                                //查询物理id关系表，为空则再调用酒店详情接口更新物理id关系表，再次查询id关系表获取roomId
                                String thisRealRoomId = mtHotelRoomNameService.goodsInfosCheckReturnGoodsRealRoomId(oneHotelRooms,mtHotelDetailVo,String.valueOf(hotelId),goodsBaseRoom,goodsBaseInfoVo.getGoodsId());
                                if(!ObjectUtil.isEmpty(thisRealRoomId)){
                                    goodsEntity.setMtRoomId(thisRealRoomId);
                                    goodsBaseInfoVo.setRoomId(thisRealRoomId);
                                }else{
                                    goodsEntity.setMtRoomId(goodsBaseRoom.get(0).getRoomId());
                                    goodsBaseInfoVo.setRoomId(goodsBaseRoom.get(0).getRoomId());
                                    log.error("checkHotelGoodsFail ////////////////  error  异常，未找到产品的realRoomId，请人工核实！！！！！："+GsonUtils.GsonString(goodsBaseInfoVo));
                                }
                            }

                            if(null == goodsEntity.getMtRoomId()){
                                log.info("/////////////////////////////  null == goodsEntity.getMtRoomId() :   {} ", JSON.toJSONString(goodsBaseInfoVo));
                            }

                            goodsEntity.setMtNeedRealTel(goodsBaseInfoVo.getNeedRealTel());
                            goodsEntity.setMtGoodsStatus(goodsBaseInfoVo.getGoodsStatus());
                            goodsEntity.setMtGoodsType(goodsBaseInfoVo.getGoodsType());
                            goodsEntity.setMtConfirmType(goodsBaseInfoVo.getConfirmType());
                            goodsEntity.setMtAveragePrice(goodsBaseInfoVo.getAveragePrice());
                            goodsEntity.setMtOriginalPrice(goodsBaseInfoVo.getOriginalPrice());
                            goodsEntity.setMtThirdParty(goodsBaseInfoVo.getThirdParty());
                            Integer needId = 0;//不需要
                            if(null != goodsBaseInfoVo.getNeedIdentityCard() && goodsBaseInfoVo.getNeedIdentityCard()==true){
                                needId = 1;//需要
                            }
                            goodsEntity.setMtNeedIdentityCard(needId);
                            goodsEntity.setMtPaymentType(goodsBaseInfoVo.getPaymentType());
                            goodsEntity.setState(CommonEnums.STATE_NORMAL.getCode());
                            goodsEntity.setRemark("");
                            goodsEntity.setMtGoodsActivity(JSON.toJSONString(goodsBaseInfoVo.getGoodsActivityMap()));
                            goodsEntity.setCreateTime(DateUtil.getNowTime());
                            goodsEntity.setModifyTime(DateUtil.getNowTime());
                            //goodsEntityList.add(goodsEntity);
                            //每个产品对应有早餐信息
                            List<MtHotelGoodsBreakfastVo> breakfastVoList = goodsBaseInfoVo.getBreakFast();
                            if(null != breakfastVoList && breakfastVoList.size()>0){
                                for (MtHotelGoodsBreakfastVo breakfastVo:breakfastVoList){
                                    MtHotelGoodsBreakfast breakfastEntity = new MtHotelGoodsBreakfast();
                                    breakfastEntity.setId(String.valueOf(UUID.randomUUID()));
                                    breakfastEntity.setMtHotelId(goodsEntity.getMtHotelId());
                                    breakfastEntity.setMtRoomId(goodsEntity.getMtRoomId());
                                    breakfastEntity.setMtGoodsId(goodsBaseInfoVo.getGoodsId());
                                    breakfastEntity.setMtBreakfastType(breakfastVo.getBreakfastType());
                                    breakfastEntity.setMtBreakfastNum(breakfastVo.getBreakfastNum());
                                    breakfastEntity.setMtStartDate(String.valueOf(breakfastVo.getInStartDate()));
                                    breakfastEntity.setMtEndDate(String.valueOf(breakfastVo.getInEndDate()));
                                    breakfastEntity.setState(CommonEnums.STATE_NORMAL.getCode());
                                    breakfastEntity.setRemark("");
                                    breakfastEntity.setCreateTime(DateUtil.getNowTime());
                                    breakfastEntity.setModifyTime(DateUtil.getNowTime());
                                    breakfastEntityList.add(breakfastEntity);
                                    //breakfastEntityDataSave.add(breakfastEntity);
                                }
                                putRedisBreakfastData.put(goodsBaseInfoVo.getGoodsId(),breakfastVoList);
                            }
                            //每个产品对应预订规则信息
                            List<MtHotelGoodsBookRuleVo> bookRuleVoList = goodsBaseInfoVo.getBookRules();
                            if(null != bookRuleVoList && bookRuleVoList.size()>0){
                                for (MtHotelGoodsBookRuleVo bookRuleVo:bookRuleVoList){
                                    MtHotelGoodsBookRule bookRule = new MtHotelGoodsBookRule();
                                    bookRule.setId(String.valueOf(UUID.randomUUID()));
                                    bookRule.setMtHotelId(goodsEntity.getMtHotelId());
                                    bookRule.setMtRoomId(goodsEntity.getMtRoomId());
                                    bookRule.setMtGoodsId(goodsBaseInfoVo.getGoodsId());
                                    bookRule.setMtSerialCheckinMin(bookRuleVo.getSerialCheckinMin());
                                    bookRule.setMtSerialCheckinMax(bookRuleVo.getSerialCheckinMax());
                                    bookRule.setMtRoomCountMin(bookRuleVo.getRoomCountMin());
                                    bookRule.setMtRoomCountMax(bookRuleVo.getRoomCountMax());
                                    bookRule.setMtEarliestBookingDays(bookRuleVo.getEarliestBookingDays());
                                    bookRule.setMtEarliestBookingHours(bookRuleVo.getEarliestBookingHours());
                                    bookRule.setMtLatestBookingDays(bookRuleVo.getLatestBookingDays());
                                    bookRule.setMtLatestBookingHours(bookRuleVo.getLatestBookingHours());
                                    bookRule.setMtIsDaybreakBooking(bookRuleVo.getIsDaybreakBooking());
                                    bookRule.setMtInStartDate(bookRuleVo.getInStartDate());
                                    bookRule.setMtInEndDate(bookRuleVo.getInEndDate());
                                    bookRule.setState(CommonEnums.STATE_NORMAL.getCode());
                                    bookRule.setRemark("");
                                    bookRule.setCreateTime(DateUtil.getNowTime());
                                    bookRule.setModifyTime(DateUtil.getNowTime());
                                    bookRuleEntityList.add(bookRule);
                                    //bookRuleEntityDataSave.add(bookRule);
                                }
                            }
                            //每个产品对应取消规则信息
                            List<MtHotelGoodsCancelRuleVo> cancelRulesVoList = goodsBaseInfoVo.getCancelRules();
                            if(null != cancelRulesVoList && cancelRulesVoList.size()>0){
                                for (MtHotelGoodsCancelRuleVo cancelVo:cancelRulesVoList){
                                    MtHotelGoodsCancelRule cancelRule = new MtHotelGoodsCancelRule();
                                    cancelRule.setId(String.valueOf(UUID.randomUUID()));
                                    cancelRule.setMtHotelId(goodsEntity.getMtHotelId());
                                    cancelRule.setMtRoomId(goodsEntity.getMtRoomId());
                                    cancelRule.setMtGoodsId(goodsBaseInfoVo.getGoodsId());
                                    cancelRule.setMtCancelType(cancelVo.getCancelType());
                                    cancelRule.setMtAheadCancelDays(cancelVo.getAheadCancelDays());
                                    cancelRule.setMtAheadCancelHours(cancelVo.getAheadCancelHours());
                                    cancelRule.setMtDeductType(cancelVo.getDeductType());
                                    cancelRule.setState(CommonEnums.STATE_NORMAL.getCode());
                                    cancelRule.setRemark("");
                                    cancelRule.setCreateTime(DateUtil.getNowTime());
                                    cancelRule.setModifyTime(DateUtil.getNowTime());
                                    cancelRuleEntityList.add(cancelRule);
                                    //cancelRuleEntityDataSave.add(cancelRule);
                                }
                            }
                            MtHotelGoodsInvoice invoice = new MtHotelGoodsInvoice();
                            if(null != goodsBaseInfoVo.getInvoiceInfo()){
                                invoice.setId(String.valueOf(UUID.randomUUID()));
                                invoice.setMtHotelId(goodsEntity.getMtHotelId());
                                invoice.setMtRoomId(goodsEntity.getMtRoomId());
                                invoice.setMtGoodsId(goodsBaseInfoVo.getGoodsId());
                                invoice.setInvoiceMode(goodsBaseInfoVo.getInvoiceInfo().getInvoiceMode());
                                invoice.setSupportTypes(JSON.toJSONString(goodsBaseInfoVo.getInvoiceInfo().getSupportTypes()));
                                invoice.setTmcInvoiceMode(goodsBaseInfoVo.getInvoiceInfo().getTmcInvoiceMode());
                                invoice.setState(CommonEnums.STATE_NORMAL.getCode());
                                invoice.setRemark("");
                                invoice.setCreateTime(DateUtil.getNowTime());
                                invoice.setModifyTime(DateUtil.getNowTime());
                                //invoiceList.add(invoice);
                                //invoiceEntityDataSave.add(invoice);
                            }

                            if("inner".equals(source)){
                                //判断是否内部接口请求
                                //构建map数据，map<key=房型id,value=mtHotelGoodsDto>
                                MtHotelGoodsDto goodsDto = new MtHotelGoodsDto();
                                BeanUtils.copyProperties(goodsEntity,goodsDto);

                                MtHotelGoodsInvoiceDto invoiceDto = new MtHotelGoodsInvoiceDto();
                                BeanUtils.copyProperties(invoice,invoiceDto);
                                goodsDto.setInvoice(invoiceDto);

                                List<MtHotelGoodsBreakfastDto> goodsBreakFastDtoList = new ArrayList<>();
                                if(null != breakfastEntityList && breakfastEntityList.size()>0){
                                    for (MtHotelGoodsBreakfast entity:breakfastEntityList){
                                        MtHotelGoodsBreakfastDto dto = new MtHotelGoodsBreakfastDto();
                                        BeanUtils.copyProperties(entity,dto);
                                        goodsBreakFastDtoList.add(dto);
                                    }
                                }
                                List<MtHotelGoodsCancelRuleDto> goodsCancelRuleDtoList = new ArrayList<>();
                                if(null != cancelRuleEntityList && cancelRuleEntityList.size()>0){
                                    for (MtHotelGoodsCancelRule entity:cancelRuleEntityList){
                                        MtHotelGoodsCancelRuleDto dto = new MtHotelGoodsCancelRuleDto();
                                        BeanUtils.copyProperties(entity,dto);
                                        goodsCancelRuleDtoList.add(dto);
                                    }
                                }
                                List<MtHotelGoodsBookRuleDto> goodsBookRuleDtoList = new ArrayList<>();
                                if(null != bookRuleEntityList && bookRuleEntityList.size()>0){
                                    for (MtHotelGoodsBookRule entity:bookRuleEntityList){
                                        MtHotelGoodsBookRuleDto dto = new MtHotelGoodsBookRuleDto();
                                        BeanUtils.copyProperties(entity,dto);
                                        goodsBookRuleDtoList.add(dto);
                                    }
                                }
                                goodsDto.setBreakfastList(goodsBreakFastDtoList);
                                goodsDto.setCancelRuleList(goodsCancelRuleDtoList);
                                goodsDto.setBookRuleList(goodsBookRuleDtoList);
                                goodsDto.setGoodsActivityMap(goodsBaseInfoVo.getGoodsActivityMap());

                                List<MtHotelGoodsDto> getDtoList = roomAboutgoodsDtosMap.get(goodsDto.getMtRoomId());
                                if(null != getDtoList && getDtoList.size()>0){
                                    getDtoList.add(goodsDto);
                                }else{
                                    getDtoList = new ArrayList<>();
                                    getDtoList.add(goodsDto);
                                }
                                roomAboutgoodsDtosMap.put(goodsDto.getMtRoomId(),getDtoList);
                            }
                        }
                    }
                }
                if("inner".equals(source)){
                    for (Map.Entry entry:roomAboutgoodsDtosMap.entrySet()){
                        MtHotelGoodsDataGroupRoomDto mtHotelGoodsDataGroupRoomDto = new MtHotelGoodsDataGroupRoomDto();
                        mtHotelGoodsDataGroupRoomDto.setMtRoomId((String)entry.getKey());
                        mtHotelGoodsDataGroupRoomDto.setMtHotelGoodsDtoData((List<MtHotelGoodsDto>)entry.getValue());
                        mtHotelGoodsListDtoArray.add(mtHotelGoodsDataGroupRoomDto);
                    }
                    return new Result<>(JacksonUtil.objectToJson(mtHotelGoodsListDtoArray),"success");
                }else{
                    return new Result<>(manyHotelGoodsVos);
                }

            }else{
                log.info("////////////////MTAPIERROR///////////////////酒店产品列表接口数据异常 hotelGoods is null");
                return new Result<>("hotelGoods null",CommonConstants.SUCCESS);
            }
        }else{
            log.error("////////////////MTAPIERROR///////////////////酒店产品列表接口数据异常 mtHotelGoodsVo is null");
            return new Result<>("mtHotelGoodsVo null",CommonConstants.SUCCESS);
        }
    }


    @Override
    public Result<Object> buildSwUpGoods(MtHotelDetailVo oneHotelDetail,List<MtHotelRealRoomVo> oneHotelRooms,MtHotelGoodsChildInfoVo oneHotelGoodsVos){

        //业务处理，保存数据
        Map<String, List<MtHotelGoodsDto>> roomAboutgoodsDtosMap = new HashMap<>();

        //遍历酒店产品信息
        Integer hotelId = oneHotelGoodsVos.getHotelId();

        List<MtHotelGoodsBaseInfoVo> goods = oneHotelGoodsVos.getGoods();
        if(null != goods && goods.size()>0){
            //多家酒店，最多查询10家；每家酒店可能存在多个产品；
            for (int i = 0; i <goods.size(); i++) {
                MtHotelGoodsBaseInfoVo goodsBaseInfoVo = goods.get(i);
                //遍历 一家酒店 - 所有产品
                MtHotelGoods goodsEntity = new MtHotelGoods();
                goodsEntity.setId(String.valueOf(UUID.randomUUID()));
                goodsEntity.setMtHotelId(String.valueOf(hotelId));
                goodsEntity.setMtGoodsId(goodsBaseInfoVo.getGoodsId());
                goodsEntity.setMtGoodsName(goodsBaseInfoVo.getGoodsName());
                List<MtHotelGoodsBaseRoomVo> goodsBaseRoom = goodsBaseInfoVo.getRoomInfoList();

                if(null != goodsBaseRoom && goodsBaseRoom.size()>0){
                    goodsEntity.setMtCityId(goodsBaseRoom.get(0).getCityId());
                    goodsEntity.setMtRoomName(goodsBaseRoom.get(0).getRoomName());
                    goodsEntity.setMtFalseRoomId(goodsBaseRoom.get(0).getRoomId());//接口的roomId为假的房型id，先保存预留

                    //查询物理id关系表，为空则再调用酒店详情接口更新物理id关系表，再次查询id关系表获取roomId
                    String thisRealRoomId = mtHotelRoomNameService.goodsInfosCheckReturnGoodsRealRoomId(oneHotelRooms,oneHotelDetail,String.valueOf(hotelId),goodsBaseRoom,goodsBaseInfoVo.getGoodsId());
                    if(!ObjectUtil.isEmpty(thisRealRoomId)){
                        goodsEntity.setMtRoomId(thisRealRoomId);
                        goodsBaseInfoVo.setRoomId(thisRealRoomId);
                    }else{
                        goodsEntity.setMtRoomId(goodsBaseRoom.get(0).getRoomId());
                        goodsBaseInfoVo.setRoomId(goodsBaseRoom.get(0).getRoomId());
                        log.error("checkHotelGoodsFail ////////////////  error  异常，未找到产品的realRoomId，请人工核实！！！！！："+GsonUtils.GsonString(goodsBaseInfoVo));
                    }
                }

                if(null == goodsEntity.getMtRoomId()){
                    log.info("/////////////////////////////  null == goodsEntity.getMtRoomId() :   {} ", JSON.toJSONString(goodsBaseInfoVo));
                }

                goodsEntity.setMtNeedRealTel(goodsBaseInfoVo.getNeedRealTel());
                goodsEntity.setMtGoodsStatus(goodsBaseInfoVo.getGoodsStatus());
                goodsEntity.setMtGoodsType(goodsBaseInfoVo.getGoodsType());
                goodsEntity.setMtConfirmType(goodsBaseInfoVo.getConfirmType());
                goodsEntity.setMtAveragePrice(goodsBaseInfoVo.getAveragePrice());
                goodsEntity.setMtOriginalPrice(goodsBaseInfoVo.getOriginalPrice());
                goodsEntity.setMtThirdParty(goodsBaseInfoVo.getThirdParty());
                Integer needId = 0;//不需要
                if(null != goodsBaseInfoVo.getNeedIdentityCard() && goodsBaseInfoVo.getNeedIdentityCard()==true){
                    needId = 1;//需要
                }
                goodsEntity.setMtNeedIdentityCard(needId);
                goodsEntity.setMtPaymentType(goodsBaseInfoVo.getPaymentType());
                goodsEntity.setMtGoodsActivity(JSON.toJSONString(goodsBaseInfoVo.getGoodsActivityMap()));

                MtHotelGoodsDto goodsDto = new MtHotelGoodsDto();
                BeanUtils.copyProperties(goodsEntity,goodsDto);

                MtHotelGoodsInvoiceDto invoiceDto = new MtHotelGoodsInvoiceDto();
                if(null != goodsBaseInfoVo.getInvoiceInfo()){
                    invoiceDto.setInvoiceMode(goodsBaseInfoVo.getInvoiceInfo().getInvoiceMode());
                    invoiceDto.setSupportTypes(JSON.toJSONString(goodsBaseInfoVo.getInvoiceInfo().getSupportTypes()));
                    invoiceDto.setTmcInvoiceMode(goodsBaseInfoVo.getInvoiceInfo().getTmcInvoiceMode());
                    goodsDto.setInvoice(invoiceDto);
                }

                List<MtHotelGoodsBreakfastDto> goodsBreakFastDtoList = new ArrayList<>();
                //每个产品对应有早餐信息
                List<MtHotelGoodsBreakfastVo> breakfastVoList = goodsBaseInfoVo.getBreakFast();
                if(null != breakfastVoList && breakfastVoList.size()>0){
                    for (MtHotelGoodsBreakfastVo breakfastVo:breakfastVoList){
                        MtHotelGoodsBreakfastDto dto = new MtHotelGoodsBreakfastDto();
                        dto.setMtHotelId(String.valueOf(hotelId));
                        dto.setMtRoomId(goodsEntity.getMtRoomId());
                        dto.setMtGoodsId(goodsBaseInfoVo.getGoodsId());
                        dto.setMtBreakfastType(breakfastVo.getBreakfastType());
                        dto.setMtBreakfastNum(breakfastVo.getBreakfastNum());
                        dto.setMtStartDate(String.valueOf(breakfastVo.getInStartDate()));
                        dto.setMtEndDate(String.valueOf(breakfastVo.getInEndDate()));
                        goodsBreakFastDtoList.add(dto);
                    }
                }

                List<MtHotelGoodsCancelRuleDto> goodsCancelRuleDtoList = new ArrayList<>();
                //每个产品对应取消规则信息
                List<MtHotelGoodsCancelRuleVo> cancelRulesVoList = goodsBaseInfoVo.getCancelRules();
                if(null != cancelRulesVoList && cancelRulesVoList.size()>0){
                    for (MtHotelGoodsCancelRuleVo cancelVo:cancelRulesVoList){
                        MtHotelGoodsCancelRuleDto dto = new MtHotelGoodsCancelRuleDto();
                        dto.setMtHotelId(goodsEntity.getMtHotelId());
                        dto.setMtRoomId(goodsEntity.getMtRoomId());
                        dto.setMtGoodsId(goodsBaseInfoVo.getGoodsId());
                        dto.setMtCancelType(cancelVo.getCancelType());
                        dto.setMtAheadCancelDays(cancelVo.getAheadCancelDays());
                        dto.setMtAheadCancelHours(cancelVo.getAheadCancelHours());
                        dto.setMtDeductType(cancelVo.getDeductType());
                        goodsCancelRuleDtoList.add(dto);
                    }
                }
                List<MtHotelGoodsBookRuleDto> goodsBookRuleDtoList = new ArrayList<>();

                //每个产品对应预订规则信息
                List<MtHotelGoodsBookRuleVo> bookRuleVoList = goodsBaseInfoVo.getBookRules();
                if(null != bookRuleVoList && bookRuleVoList.size()>0){
                    for (MtHotelGoodsBookRuleVo bookRuleVo:bookRuleVoList){
                        MtHotelGoodsBookRuleDto dto = new MtHotelGoodsBookRuleDto();
                        dto.setMtHotelId(goodsEntity.getMtHotelId());
                        dto.setMtRoomId(goodsEntity.getMtRoomId());
                        dto.setMtGoodsId(goodsBaseInfoVo.getGoodsId());
                        dto.setMtSerialCheckinMin(bookRuleVo.getSerialCheckinMin());
                        dto.setMtSerialCheckinMax(bookRuleVo.getSerialCheckinMax());
                        dto.setMtRoomCountMin(bookRuleVo.getRoomCountMin());
                        dto.setMtRoomCountMax(bookRuleVo.getRoomCountMax());
                        dto.setMtEarliestBookingDays(bookRuleVo.getEarliestBookingDays());
                        dto.setMtEarliestBookingHours(bookRuleVo.getEarliestBookingHours());
                        dto.setMtLatestBookingDays(bookRuleVo.getLatestBookingDays());
                        dto.setMtLatestBookingHours(bookRuleVo.getLatestBookingHours());
                        dto.setMtIsDaybreakBooking(bookRuleVo.getIsDaybreakBooking());
                        dto.setMtInStartDate(bookRuleVo.getInStartDate());
                        dto.setMtInEndDate(bookRuleVo.getInEndDate());
                        goodsBookRuleDtoList.add(dto);
                        //bookRuleEntityDataSave.add(bookRule);
                    }
                }
                goodsDto.setPriceModel(goodsBaseInfoVo.getPriceModels());
                goodsDto.setBreakfastList(goodsBreakFastDtoList);
                goodsDto.setCancelRuleList(goodsCancelRuleDtoList);
                goodsDto.setBookRuleList(goodsBookRuleDtoList);
                goodsDto.setGoodsActivityMap(goodsBaseInfoVo.getGoodsActivityMap());

                List<MtHotelGoodsDto> getDtoList = roomAboutgoodsDtosMap.get(goodsDto.getMtRoomId());
                if(null != getDtoList && getDtoList.size()>0){
                    getDtoList.add(goodsDto);
                }else{
                    getDtoList = new ArrayList<>();
                    getDtoList.add(goodsDto);
                }
                roomAboutgoodsDtosMap.put(goodsDto.getMtRoomId(),getDtoList);
            }
        }
        return new Result<>(GsonUtils.GsonString(roomAboutgoodsDtosMap),"success");
    }

    @Override
    public Result<Object> getTendHotelGoodsInfoForJob(List<Long> hotelList) {
        Result<Object> apiResult = null;
        try{
            Integer days = this.getDaysCommonBaseSetForVip();//当前默认查2天
            MtHotelGoodsSpecParamVo mtHotelGoodsSpecParamVo = new MtHotelGoodsSpecParamVo();
            mtHotelGoodsSpecParamVo.setGoodsType(MtGoodsEnums.roomDateTypeEnum.DAY.getCode());
            mtHotelGoodsSpecParamVo.setCheckinDate(DateUtil.formatDate(new Date(),"yyyy-MM-dd"));
            mtHotelGoodsSpecParamVo.setCheckoutDate(DateUtil.formatDate(DateUtil.addDay(new Date(),days),"yyyy-MM-dd"));
            apiResult = this.getMtHotelGoods(null,hotelList,mtHotelGoodsSpecParamVo.getCheckinDate(),mtHotelGoodsSpecParamVo.getCheckoutDate(),mtHotelGoodsSpecParamVo.getGoodsType());
            if(apiResult.getCode()==CommonConstants.SUCCESS){
                return new Result<>(apiResult.getData());
            }
        }catch (Exception e){
            log.error("findMtGoodsCheckUpDown getMtGoodsByHotelIdForJob 异常："+e.getMessage()+",apiResult="+GsonUtils.GsonString(apiResult));
            apiResult = new Result<>("error:"+e.getMessage());
            e.printStackTrace();
        }
        return apiResult;
    }

    @Override
    public SwitchCreateRoomDto requestSwitchsGoodsRoomInfoByRoomId(String goodsId) {
        String host = CommonUrlConstants.MEITUAN_HOST;
        String method = UrlInnerEnums.switchRoom.GET_ROOM_BY_ID.getValue();
        String url = host+method;
        //发起请求
        Result response = RestTemplateUtils.post(url, JSON.toJSONString(goodsId),restTemplate);
        SwitchCreateRoomDto dto = null;
        if(null != response.getData()){
            dto = JSON.parseObject(response.getData().toString(),SwitchCreateRoomDto.class);
        }
        return dto;
    }

    /**
     * 保存产品相关数据-接口返回的产品相关数据-供定时器每日更新静态信息调用
     * @param manyHotelGoodsData
     * @return
     */
    @Override
    public Result<Object> saveMtGoodsData(String source,MtHotelGoodsVo manyHotelGoodsData){
        if(null != manyHotelGoodsData && null != manyHotelGoodsData.getHotelGoods() && manyHotelGoodsData.getHotelGoods().size()>0){
            List<Long> hotelIds = new ArrayList<>();
            for (MtHotelGoodsChildInfoVo h:manyHotelGoodsData.getHotelGoods()){
                hotelIds.add(Long.valueOf(h.getHotelId()));
            }
           /* Map<String,MtHotelDetailVo> hotelsMap = new HashMap<>();
            List<MtHotelDetailVo> hotelDetailArray = mtHotelRoomNameService.returnHotelDetailRoomList(hotelIds);
            if(null != hotelDetailArray && hotelDetailArray.size()>0){
                for (MtHotelDetailVo h:hotelDetailArray){
                    hotelsMap.put(String.valueOf(h.getBaseInfo().getHotelId()),h);
                }
            }*/

            //业务处理，保存数据
            List<MtHotelGoodsChildInfoVo> manyHotelGoodsArray = manyHotelGoodsData.getHotelGoods();
            if(null != manyHotelGoodsArray && manyHotelGoodsArray.size()>0){//多个酒店则数组大于1
                for(MtHotelGoodsChildInfoVo oneHotelGoodsVo:manyHotelGoodsArray){
                    //遍历酒店产品信息
                    Integer hotelId = oneHotelGoodsVo.getHotelId();
                    List<MtHotelGoodsBaseInfoVo> goods = oneHotelGoodsVo.getGoods();
                    List<MtHotelGoods> goodsEntityList = new ArrayList<>();
                    List<MtHotelGoodsBreakfast> breakfastEntityDataSave = new ArrayList<>();
                    Map<String,List<MtHotelGoodsBreakfastVo>> putRedisBreakfastData = new HashMap<>();
                    List<MtHotelGoodsBookRule> bookRuleEntityDataSave = new ArrayList<>();
                    List<MtHotelGoodsCancelRule> cancelRuleEntityDataSave = new ArrayList<>();
                    List<MtHotelGoodsInvoice> invoiceEntityDataSave = new ArrayList<>();
                    if(null != goods && goods.size()>0){
                        //多家酒店，最多查询10家；每家酒店可能存在多个产品；

                        for (int i = 0; i <goods.size(); i++) {
                            MtHotelGoodsBaseInfoVo goodsBaseInfoVo = goods.get(i);
                            List<MtHotelGoodsBreakfast> breakfastEntityList = new ArrayList<>();
                            List<MtHotelGoodsBookRule> bookRuleEntityList = new ArrayList<>();
                            List<MtHotelGoodsCancelRule> cancelRuleEntityList = new ArrayList<>();
                            List<MtHotelGoodsInvoice> invoiceList = new ArrayList<>();
                            //遍历 一家酒店 - 所有产品
                            MtHotelGoods goodsEntity = new MtHotelGoods();
                            goodsEntity.setId(String.valueOf(UUID.randomUUID()));
                            goodsEntity.setMtHotelId(String.valueOf(hotelId));
                            goodsEntity.setMtGoodsId(goodsBaseInfoVo.getGoodsId());
                            goodsEntity.setMtGoodsName(goodsBaseInfoVo.getGoodsName());
                            List<MtHotelGoodsBaseRoomVo> goodsBaseRoom = goodsBaseInfoVo.getRoomInfoList();

                            log.info("/////////////////////////////  goodsBaseInfoVo.getRoomInfoList() :   {} ", JSON.toJSONString(goodsBaseRoom));
                            /*if(null != goodsBaseRoom && goodsBaseRoom.size()>0){
                             *//*if(goodsBaseRoom.size()>1){
                                    //上游标识每个产品只对应一个房间信息,但返回的是list，特殊处理
                                    log.error("////////////////MTAPIERROR///////////////////酒店产品列表接口数据异常 goodsBaseRoom size >1");
                                    //return new Result<>("goodsBaseRoom error overstep", CommonConstants.PARSE_ERROR);
                                }else{

                                }*//*
                                goodsEntity.setMtCityId(goodsBaseRoom.get(0).getCityId());
                                goodsEntity.setMtRoomName(goodsBaseRoom.get(0).getRoomName());
                                goodsEntity.setMtFalseRoomId(goodsBaseRoom.get(0).getRoomId());//接口的roomId为假的房型id，先保存预留

                                //查询物理id关系表，为空则再调用酒店详情接口更新物理id关系表，再次查询id关系表获取roomId
                                //先拿缓存，有则返回，无则调用物理房型接口再set缓存
                                String thisRealRoomId = mtHotelRoomNameService.goodsInfosCheckReturnGoodsRealRoomId(hotelDetails,String.valueOf(hotelId),goodsBaseRoom,goodsBaseInfoVo.getGoodsId());
                                if(!ObjectUtil.isEmpty(thisRealRoomId)){
                                    goodsEntity.setMtRoomId(thisRealRoomId);
                                    goodsBaseInfoVo.setRoomId(thisRealRoomId);
                                }else{
                                    goodsEntity.setMtRoomId(goodsBaseRoom.get(0).getRoomId());
                                    goodsBaseInfoVo.setRoomId(goodsBaseRoom.get(0).getRoomId());
                                    log.error("checkHotelGoodsFail ////////////////  error  异常，未找到产品的realRoomId，请人工核实！！！！！："+GsonUtils.GsonString(goodsBaseInfoVo));

                                }
                            }*/

                            if(null == goodsEntity.getMtRoomId()){/////目前该保存方法 就每天定时器保存一次，，定时器当下校验到的realroomid要赋值到goodsEntity.getMtRoomId(),,当前保存不再查询realyroomid
                                log.info("/////////////////////////////  null == goodsEntity.getMtRoomId() :   {} ", JSON.toJSONString(goodsBaseInfoVo));
                            }

                            goodsEntity.setMtNeedRealTel(goodsBaseInfoVo.getNeedRealTel());
                            goodsEntity.setMtGoodsStatus(goodsBaseInfoVo.getGoodsStatus());
                            goodsEntity.setMtGoodsType(goodsBaseInfoVo.getGoodsType());
                            goodsEntity.setMtConfirmType(goodsBaseInfoVo.getConfirmType());
                            goodsEntity.setMtAveragePrice(goodsBaseInfoVo.getAveragePrice());
                            goodsEntity.setMtOriginalPrice(goodsBaseInfoVo.getOriginalPrice());
                            goodsEntity.setMtThirdParty(goodsBaseInfoVo.getThirdParty());
                            Integer needId = 0;//不需要
                            if(null != goodsBaseInfoVo.getNeedIdentityCard() && goodsBaseInfoVo.getNeedIdentityCard()==true){
                                needId = 1;//需要
                            }
                            goodsEntity.setMtNeedIdentityCard(needId);
                            goodsEntity.setMtPaymentType(goodsBaseInfoVo.getPaymentType());
                            goodsEntity.setState(CommonEnums.STATE_NORMAL.getCode());
                            goodsEntity.setRemark("");
                            goodsEntity.setMtGoodsActivity(JSON.toJSONString(goodsBaseInfoVo.getGoodsActivityMap()));
                            goodsEntity.setCreateTime(DateUtil.getNowTime());
                            goodsEntity.setModifyTime(DateUtil.getNowTime());
                            goodsEntityList.add(goodsEntity);
                            /*sb.append("'"+goodsEntity.getMtGoodsId()+"'");
                            if(i!=goods.size()-1){
                                sb.append(",");
                            }*/
                            //每个产品对应有早餐信息
                            List<MtHotelGoodsBreakfastVo> breakfastVoList = goodsBaseInfoVo.getBreakFast();
                            if(null != breakfastVoList && breakfastVoList.size()>0){
                                for (MtHotelGoodsBreakfastVo breakfastVo:breakfastVoList){
                                    MtHotelGoodsBreakfast breakfastEntity = new MtHotelGoodsBreakfast();
                                    breakfastEntity.setId(String.valueOf(UUID.randomUUID()));
                                    breakfastEntity.setMtHotelId(goodsEntity.getMtHotelId());
                                    breakfastEntity.setMtRoomId(goodsEntity.getMtRoomId());
                                    breakfastEntity.setMtGoodsId(goodsBaseInfoVo.getGoodsId());
                                    breakfastEntity.setMtBreakfastType(breakfastVo.getBreakfastType());
                                    breakfastEntity.setMtBreakfastNum(breakfastVo.getBreakfastNum());
                                    breakfastEntity.setMtStartDate(String.valueOf(breakfastVo.getInStartDate()));
                                    breakfastEntity.setMtEndDate(String.valueOf(breakfastVo.getInEndDate()));
                                    breakfastEntity.setState(CommonEnums.STATE_NORMAL.getCode());
                                    breakfastEntity.setRemark("");
                                    breakfastEntity.setCreateTime(DateUtil.getNowTime());
                                    breakfastEntity.setModifyTime(DateUtil.getNowTime());
                                    breakfastEntityList.add(breakfastEntity);
                                    breakfastEntityDataSave.add(breakfastEntity);
                                }
                                putRedisBreakfastData.put(goodsBaseInfoVo.getGoodsId(),breakfastVoList);
                            }
                            //每个产品对应预订规则信息
                            List<MtHotelGoodsBookRuleVo> bookRuleVoList = goodsBaseInfoVo.getBookRules();
                            if(null != bookRuleVoList && bookRuleVoList.size()>0){
                                for (MtHotelGoodsBookRuleVo bookRuleVo:bookRuleVoList){
                                    MtHotelGoodsBookRule bookRule = new MtHotelGoodsBookRule();
                                    bookRule.setId(String.valueOf(UUID.randomUUID()));
                                    bookRule.setMtHotelId(goodsEntity.getMtHotelId());
                                    bookRule.setMtRoomId(goodsEntity.getMtRoomId());
                                    bookRule.setMtGoodsId(goodsBaseInfoVo.getGoodsId());
                                    bookRule.setMtSerialCheckinMin(bookRuleVo.getSerialCheckinMin());
                                    bookRule.setMtSerialCheckinMax(bookRuleVo.getSerialCheckinMax());
                                    bookRule.setMtRoomCountMin(bookRuleVo.getRoomCountMin());
                                    bookRule.setMtRoomCountMax(bookRuleVo.getRoomCountMax());
                                    bookRule.setMtEarliestBookingDays(bookRuleVo.getEarliestBookingDays());
                                    bookRule.setMtEarliestBookingHours(bookRuleVo.getEarliestBookingHours());
                                    bookRule.setMtLatestBookingDays(bookRuleVo.getLatestBookingDays());
                                    bookRule.setMtLatestBookingHours(bookRuleVo.getLatestBookingHours());
                                    bookRule.setMtIsDaybreakBooking(bookRuleVo.getIsDaybreakBooking());
                                    bookRule.setMtInStartDate(bookRuleVo.getInStartDate());
                                    bookRule.setMtInEndDate(bookRuleVo.getInEndDate());
                                    bookRule.setState(CommonEnums.STATE_NORMAL.getCode());
                                    bookRule.setRemark("");
                                    bookRule.setCreateTime(DateUtil.getNowTime());
                                    bookRule.setModifyTime(DateUtil.getNowTime());
                                    bookRuleEntityList.add(bookRule);
                                    bookRuleEntityDataSave.add(bookRule);
                                }
                            }
                            //每个产品对应取消规则信息
                            List<MtHotelGoodsCancelRuleVo> cancelRulesVoList = goodsBaseInfoVo.getCancelRules();
                            if(null != cancelRulesVoList && cancelRulesVoList.size()>0){
                                for (MtHotelGoodsCancelRuleVo cancelVo:cancelRulesVoList){
                                    MtHotelGoodsCancelRule cancelRule = new MtHotelGoodsCancelRule();
                                    cancelRule.setId(String.valueOf(UUID.randomUUID()));
                                    cancelRule.setMtHotelId(goodsEntity.getMtHotelId());
                                    cancelRule.setMtRoomId(goodsEntity.getMtRoomId());
                                    cancelRule.setMtGoodsId(goodsBaseInfoVo.getGoodsId());
                                    cancelRule.setMtCancelType(cancelVo.getCancelType());
                                    cancelRule.setMtAheadCancelDays(cancelVo.getAheadCancelDays());
                                    cancelRule.setMtAheadCancelHours(cancelVo.getAheadCancelHours());
                                    cancelRule.setMtDeductType(cancelVo.getDeductType());
                                    cancelRule.setState(CommonEnums.STATE_NORMAL.getCode());
                                    cancelRule.setRemark("");
                                    cancelRule.setCreateTime(DateUtil.getNowTime());
                                    cancelRule.setModifyTime(DateUtil.getNowTime());
                                    cancelRuleEntityList.add(cancelRule);
                                    cancelRuleEntityDataSave.add(cancelRule);
                                }
                            }
                            MtHotelGoodsInvoice invoice = new MtHotelGoodsInvoice();
                            if(null != goodsBaseInfoVo.getInvoiceInfo()){
                                invoice.setId(String.valueOf(UUID.randomUUID()));
                                invoice.setMtHotelId(goodsEntity.getMtHotelId());
                                invoice.setMtRoomId(goodsEntity.getMtRoomId());
                                invoice.setMtGoodsId(goodsBaseInfoVo.getGoodsId());
                                invoice.setInvoiceMode(goodsBaseInfoVo.getInvoiceInfo().getInvoiceMode());
                                invoice.setSupportTypes(JSON.toJSONString(goodsBaseInfoVo.getInvoiceInfo().getSupportTypes()));
                                invoice.setTmcInvoiceMode(goodsBaseInfoVo.getInvoiceInfo().getTmcInvoiceMode());
                                invoice.setState(CommonEnums.STATE_NORMAL.getCode());
                                invoice.setRemark("");
                                invoice.setCreateTime(DateUtil.getNowTime());
                                invoice.setModifyTime(DateUtil.getNowTime());
                                invoiceList.add(invoice);
                                invoiceEntityDataSave.add(invoice);
                            }

                        }

                        if(null != goodsEntityList && goodsEntityList.size()>0){
                            //Map<产品id,产品早餐规则集合>  putRedisBreakfastData
                            /*Map<String,List<MtHotelGoodsBreakfastVo>> redisMap = (Map<String,List<MtHotelGoodsBreakfastVo>>)redisService.get(CommonConstants.MEITUAN_HOTEL_GOODS_BREAKFAST_LIST);
                            if(null != redisMap && redisMap.size()>0){
                                redisMap.putAll(putRedisBreakfastData);
                            }else{
                                redisMap = putRedisBreakfastData;
                            }
                            redisService.set(CommonConstants.MEITUAN_HOTEL_GOODS_BREAKFAST_LIST,redisMap);*/

                            //旧数据删除，插入新数据
                            Map map = new HashMap();
                            map.put("hotelId",hotelId);
                            int del = mtHotelGoodsMapper.deleteBatchByHotelId(map);
                            if(del!=-1){
                                try{
                                    mtHotelGoodsMapper.insertList(goodsEntityList);
                                }catch (Exception e){
                                    log.error("//////////////////////////////////错误   ："+ JSON.toJSONString(goodsEntityList));
                                    e.printStackTrace();
                                }
                            }
                        }
                        if(null != breakfastEntityDataSave && breakfastEntityDataSave.size()>0){
                            Map map = new HashMap();
                            map.put("hotelId",hotelId);
                            int brDel = mtHotelGoodsBreakfastMapper.deleteBatchByHotelId(map);
                            if(brDel!=-1){
                                mtHotelGoodsBreakfastMapper.insertList(breakfastEntityDataSave);
                            }
                        }
                        if(null != cancelRuleEntityDataSave && cancelRuleEntityDataSave.size()>0){
                            Map map = new HashMap();
                            map.put("hotelId",hotelId);
                            int canDel =  mtHotelGoodsCancelRuleMapper.deleteBatchByHotelId(map);
                            if(canDel!=-1){
                                mtHotelGoodsCancelRuleMapper.insertList(cancelRuleEntityDataSave);
                            }
                        }
                        if(null != invoiceEntityDataSave && invoiceEntityDataSave.size()>0){
                            Map map = new HashMap();
                            map.put("hotelId",hotelId);
                            int canDel =  mtHotelGoodsInvoiceMapper.deleteBatchByHotelId(map);
                            if(canDel!=-1){
                                mtHotelGoodsInvoiceMapper.insertList(invoiceEntityDataSave);
                            }
                        }
                        if(null != bookRuleEntityDataSave && bookRuleEntityDataSave.size()>0){
                            Map map = new HashMap();
                            map.put("hotelId",hotelId);
                            int BoDel = mtHotelGoodsBookRuleMapper.deleteBatchByHotelId(map);
                            if(BoDel!=-1){
                                mtHotelGoodsBookRuleMapper.insertList(bookRuleEntityDataSave);
                            }
                        }
                    }
                }

                return new Result<>(manyHotelGoodsData);

            }else{
                log.info("////////////////MTAPIERROR///////////////////酒店产品列表接口数据异常 hotelGoods is null");
                return new Result<>("hotelGoods null",CommonConstants.SUCCESS);
            }
        }else{
            log.error("////////////////MTAPIERROR///////////////////酒店产品列表接口数据异常 mtHotelGoodsVo is null");
            return new Result<>("mtHotelGoodsVo null",CommonConstants.SUCCESS);
        }
    }

    @Override
    public Result<Object> saveDealGoodsFromJob(List<MtHotelGoodsCallbackVo> goods) {
        log.info("进入保存更新变更的产品信息，MtHotelGoodsServicelmpl saveDealGoodsFromJob ");
        //当前传过来的 goods  是每次上游推送一个notify数据过来;一般来说调用该接口的数据都是需要价格修改的，数据来源美团异步通知；定时器处理缓存的异步通知数据调用该接口；异步通知时已过滤为售卖房型数据

        /**
         * 是售卖房型里的产品才需要更新保存产品信息
         * 判断是否售卖房型里的产品，才进行后续对比价格操作：
         */
        String mtHotelId = null;
        List<MtHotelGoodsPriceBaseDetailVo> thisHotelGoodsPriceModelsChanges = new ArrayList<>();
        Map<String, List<MtHotelGoodsBreakfastVo>> putBreakfastMap = new HashMap<>();
        for (MtHotelGoodsCallbackVo vo:goods){
            String goodsId = vo.getGoodsId();
            mtHotelId = vo.getHotelId();
            //switchs  查询携程售卖房型表是否存在当前美团产品
            if(requestGetSwitchsSaleRoomByMtGoodsInfo(Integer.valueOf(goodsId),mtHotelId)){//再次校验是否存在的售卖房型
                //判断价格是否有变更，遍历该售卖产品所有价格日历
                List<MtHotelGoodsPriceBaseDetailVo> priceModels = vo.getPriceModels();
                if(null != priceModels && priceModels.size()>0){//有值就有变化
                    log.info("进入保存更新变更的产品信息，MtHotelGoodsServicelmpl saveDealGoodsFromJob ，当前存在有价格变化的异步通知数据 priceModels ");
                    for (MtHotelGoodsPriceBaseDetailVo thisPriceDetailVo:priceModels){
                        //该产品该日期的价格发送改变，推送携程
                        thisPriceDetailVo.setGoodsId(Integer.valueOf(goodsId));
                        thisPriceDetailVo.setHotelId(Integer.valueOf(mtHotelId));
                        thisHotelGoodsPriceModelsChanges.add(thisPriceDetailVo);
                        /*Boolean isChange = this.checkMtGoodsChange(mtHotelId,Integer.valueOf(goodsId),thisPriceDetailVo.getDate(),thisPriceDetailVo.getSalePrice());
                        if(isChange){
                            //该产品该日期的价格发送改变，推送携程
                            thisPriceDetailVo.setGoodsId(Integer.valueOf(goodsId));
                            thisHotelGoodsPriceModelsChanges.add(thisPriceDetailVo);
                        }else{
                            log.info("进入保存更新变更的产品信息，MtHotelGoodsServicelmpl saveDealGoodsFromJob ，当前为价格变化的异步通知数据集合，其中程序和库表对比判断无变化是： {}",JSON.toJSONString(thisPriceDetailVo));
                            //无变化不做处理
                        }*/
                    }

                }
                //早餐等其他规则的变化
                //每个产品对应早餐信息
                if (null != vo.getBreakFast() && vo.getBreakFast().size() > 0) {
                    putBreakfastMap.put(mtHotelId+"_"+goodsId,vo.getBreakFast());//goodsId不是唯一所以要加上酒店id
                }
            }else{
                log.info("进入保存更新变更的产品信息，MtHotelGoodsServicelmpl saveDealGoodsFromJob 最后一次校验是否存在售卖房型不通过，不处理：{}", JSON.toJSONString(goods));
            }
        }
        if(null != putBreakfastMap && putBreakfastMap.size()>0){
            log.info("saveDealGoodsFromJob putBreakfastMap size:{}",putBreakfastMap.size());
            Map<String, List<MtHotelGoodsBreakfastVo>> redisMap = (Map<String, List<MtHotelGoodsBreakfastVo>>)redisService.get(SwitchConstants.REDIS_SWITCH_HOTEL_CHANGE_BREAKFAST);
            if(null != redisMap && redisMap.size()>0){
                redisMap.putAll(putBreakfastMap);
            }else{
                redisMap = putBreakfastMap;
            }
            //当前接收到的变更商品的早餐信息：
            //放到缓存，定时器每天凌晨跑一次
            redisService.set(SwitchConstants.REDIS_SWITCH_HOTEL_CHANGE_BREAKFAST,redisMap);
        }
        if(null != thisHotelGoodsPriceModelsChanges && thisHotelGoodsPriceModelsChanges.size()>0){
            log.info("saveDealGoodsFromJob thisHotelGoodsPriceModelsChanges size:{}",thisHotelGoodsPriceModelsChanges.size());
            //log.info("saveDealGoodsFromJob thisHotelGoodsPriceModelsChanges size:{}",thisHotelGoodsPriceModelsChanges.size());
            //SendUtils.dingMsg("【主动JOB-商品价格变化了-请人工关注】",JSON.toJSONString(thisHotelGoodsPriceModelsChanges),3);
            //swithcs 当前该售卖产品存在价格日历发送改变，批量推送携程/////多天的价格变化，多个推送，批量多天价格变化
            requestSwitchsModifyPricesAboutOneHotelGoodList(thisHotelGoodsPriceModelsChanges);
            //meituan  更新保存当前该售卖产品相关数据(价格，早餐规则，取消规则等),,,调一下当前酒店的 产品列表接口+价格日历接口（默认一个月）
            reGetMtGoodsAndPriceApi(mtHotelId);
        }
        return new Result<>();
    }

    /**
     * 重新调用酒店的产品列表和价格日历接口，则数据库该酒店的产品相关数据会进行更新
     * @param hotelId
     */
    public void reGetMtGoodsAndPriceApi(String hotelId){
        MtHotelGoodsSpecParamVo mtHotelGoodsSpecParamVo = new MtHotelGoodsSpecParamVo();
        mtHotelGoodsSpecParamVo.setHotelId(Long.valueOf(hotelId));
        mtHotelGoodsSpecParamVo.setGoodsType(MtGoodsEnums.roomDateTypeEnum.DAY.getCode());
        Result result = this.getMtGoodsByHotelId(mtHotelGoodsSpecParamVo);
        if(result.getCode()==CommonConstants.SUCCESS){
            //保存产品信息（不在get方法里保存另起方法）
            /*Result<Object> result1 = this.saveGoodsData("inner",(MtHotelGoodsVo)result.getData());
            if(null != result1 && result1.getCode()==CommonConstants.SUCCESS){

            }else{

            }*//// 2020-10-28 qyy 其他接口不做保存操作，查询产品校验上下线定时器做保存操作需要对比数据
        }else{

        }

        //上游要求：业务参数，hotelId和goodsId传其一，最好hotelId，个数支持最多10
        //我们这边最好让下游都hotelId和goodsId都上送，，，上游有返回entity对应hotelId
        List<Long> hotelIdList = new ArrayList<>();
        hotelIdList.add(Long.valueOf(hotelId));
        //时间参数为空 默认30天
        String startDate = DateUtil.formatDate(new Date(),"yyyy-MM-dd");
        String endDate = DateUtil.formatDate(DateUtil.addDay(new Date(),30),"yyyy-MM-dd");
        Result pirceRes = this.saveGetMtHotelGoodsPrice(hotelIdList,null,startDate,endDate,null);


    }

    public MtHotelGoodsPrice selectGoodsPriceByGoodsInfoAndTime(String mtGoodsId,String mtHotelId,String time){
        MtHotelGoodsPrice r = new MtHotelGoodsPrice();
        r.setMtHotelId(mtHotelId);
        r.setMtGoodsId(mtGoodsId);
        r.setMtDate(time);
        Example example = new Example(MtHotelGoodsPrice.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("mtGoodsId",mtGoodsId);
        criteria.andEqualTo("mtHotelId",mtHotelId);
        criteria.andEqualTo("mtDate",time);
        MtHotelGoodsPrice price = null;
        try{
            //List<MtHotelGoodsPrice> list= mtHotelGoodsPriceMapper.select(r);
            price= mtHotelGoodsPriceMapper.selectOneByExample(example);
        }catch (Exception e){
            log.info("selectGoodsPriceByGoodsInfoAndTime 异常！！！查询价格用来对比:{}，{}，{}",mtGoodsId,mtHotelId,time);
            e.printStackTrace();
        }

        return price;
    }

    @Override
    public boolean requestGetSwitchsSaleRoomByMtGoodsInfo(Integer goodsId,String mtHotelId) {
        //缓存了所有售卖房型redis，一级缓存  key = mtHotelId+mtGoodsId
        String existThisSaleRoom = (String)redisService.get(mtHotelId+"_"+goodsId);
        return null != existThisSaleRoom;
        /*String host = CommonUrlConstants.SWITCHS_HOST;
        String saveCallbackGoodsRpUrl = host+ UrlMtEnums.mtDealNotifyGoods.QUERY_SALE_ROOM.getValue()+"?access_token="+HttpClientBaseAuth.getAuthToken();
        log.info("查询携程售卖房型表是否存在当前美团产品 requestGetSwitchsSaleRoomByMtGoodsInfo");
        Map params = new HashMap();
        params.put("mtGoodsId",goodsId);
        params.put("mtHotelId",mtHotelId);
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.valueOf("application/json;UTF-8"));
        HttpEntity<String> strEntity = new HttpEntity<String>(JSON.toJSONString(params),headers);
        RestTemplate restTemplate = new RestTemplate();
        //发起请求
        Result response = null;
        try{
            response = restTemplate.postForObject(saveCallbackGoodsRpUrl,strEntity,Result.class);
            if(null != response && null != response.getData()){
                SwitchCreateRoomDto switchCreateRoomDto = (SwitchCreateRoomDto)response.getData();
                if(null != switchCreateRoomDto && switchCreateRoomDto.getMtGoodId() == goodsId){
                    log.info("查询携程售卖房型表  存在携程对应售卖房型 :goodsId={},mtHotelId={}",goodsId,mtHotelId);
                    return true;
                }
            }
        }catch (Exception e){
            log.error("查询携程售卖房型 requestGetSwitchsSaleRoomByMtGoodsInfo 发起请求 异常 catch: {},{}",
                    saveCallbackGoodsRpUrl,JSON.toJSONString(params),JSON.toJSONString(response));
            log.error(e.getMessage(),e);
        }
        log.info("查询携程售卖房型表是否存在当前美团产品 requestGetSwitchsSaleRoomByMtGoodsInfo   该产品未找到携程对应售卖房型，不做处理:goodsId={},mtHotelId={}",goodsId,mtHotelId);
        return false;*/
    }

    @Override
    public Result pullTodayGoodsPriceAboutCompareHotel(Integer maxPrice) {
        if(null == maxPrice){//单位分
            maxPrice = (Integer) redisService.get("get_hotel_goods_maxPrice_");
            if(null == maxPrice){
                maxPrice = 35000;
                log.info("pullTodayGoodsPriceAboutCompareHotel  未获取到 指定的maxPrice，当前默认为 35000分，350元");
            }
        }

        //获取所有有效的未创建子酒店的酒店数据（数据来源对比表）
        String compareHost = CommonUrlConstants.COMPARE_HOST;
        String hotelUrl = compareHost+ UrlMtEnums.compareHotel.GET_NOT_CREATE_COMPARE_HOTEL.getValue();
        //发起请求
        Result hotelResponse = RestTemplateUtils.post(hotelUrl,null,restTemplate);//请求返回有所未创建过子酒店的美团id接口
        if(hotelResponse.getCode() == CommonConstants.SUCCESS){//判断请求是否成功
            String startDate = DateUtil.formatDate(new Date(),"yyyy-MM-dd");//获取当前时间
            String endDate = DateUtil.formatDate(DateUtil.addDay(new Date(),1),"yyyy-MM-dd");//当前时间+1天作为结束时间
            if(null != hotelResponse.getData()){//获取响应回来的内容
                List<Long> hotelIdsList = (List<Long>)hotelResponse.getData();//把响应回来的内容转为<Long>泛型的集合
                log.info("获取所有有效的未创建子酒店的酒店数据 pullTodayGoodsPriceAboutCompareHotel  hotelIdsList.size:{}",hotelIdsList.size());
                if(null != hotelIdsList && hotelIdsList.size()>0){
                    List<Long> hotelIdData = new ArrayList<>();
                    for (int i = 1; i <= hotelIdsList.size(); i++) {
                        String hasHotel1 = (String)redisTemplate.opsForValue().get("pullTodayGoodsPriceAboutCompareHotel_data_"+hotelIdsList.get(i-1)+"_"+startDate);
                        if(null != hasHotel1){
                            continue;
                        }
                        hotelIdData.add(hotelIdsList.get(i-1));
                        //产品价格接口，每次最多十家酒店
                        if(hotelIdData.size()%10==0 || i==hotelIdsList.size()){
                            Map<String,Integer> thisAllMap = new HashMap();
                            for (int j = 0; j < hotelIdData.size(); j++) {
                                thisAllMap.put(String.valueOf(hotelIdData.get(j)),1);
                            }
                            log.info("获取所有有效的未创建子酒店的酒店数据 pullTodayGoodsPriceAboutCompareHotel  i%10==0 || i==hotelIdsList.size()，i={},hotelIdData.size:{}",i,hotelIdData.size());
                            //调用接口 产品价格日历今日价格,,每次最多十个酒店（7200次每分钟/5000000次一天=每秒120次每秒）（（产品信息接口7200/3000000））
                            Result goodsPriceResult = saveGetMtHotelGoodsPrice(hotelIdData,null,startDate,endDate,"saveGoodsPriceToCompareCreateSub");
                            if(null != goodsPriceResult && goodsPriceResult.getCode()==CommonConstants.SUCCESS){
                                if(null != goodsPriceResult.getData()){
                                    List<MtHotelGoodsPriceBaseVo> goodsPrices = (List<MtHotelGoodsPriceBaseVo>)goodsPriceResult.getData();
                                    if(null != goodsPrices && goodsPrices.size()>0){
                                        for (MtHotelGoodsPriceBaseVo mtHotelGoodsPriceBaseVo : goodsPrices){
                                            //价格日历接口返回的是 一个mtHotelGoodsPriceBaseVo 表示一个产品（酒店id+产品id） ，mtHotelGoodsPriceBaseVo.getPriceModels() 多组产品价格信息，
                                            String hasHotel = (String)redisTemplate.opsForValue().get("pullTodayGoodsPriceAboutCompareHotel_data_"+mtHotelGoodsPriceBaseVo.getHotelId()+"_"+startDate);
                                            if(null != hasHotel){
                                                continue;
                                            }
                                            String hasHotelNot = (String)redisTemplate.opsForValue().get("pullTodayGoodsPriceAboutCompareHotel_no_data_"+mtHotelGoodsPriceBaseVo.getHotelId()+"_"+startDate);
                                            if(null != hasHotelNot){
                                                continue;
                                            }
                                            for (MtHotelGoodsPriceBaseDetailVo priceDetail:mtHotelGoodsPriceBaseVo.getPriceModels()){
                                                //循环每个产品的今日价格 只上送今天所以getPriceModels 集合为1
                                                if(priceDetail.getSalePrice()<=maxPrice){//单位分
                                                    //该酒店的某一个产品有等于250就保存跳出循环不再校验该酒店其他产品
                                                    MtHotelGoodsPriceDays mtHotelGoodsPriceDays = new MtHotelGoodsPriceDays();
                                                    mtHotelGoodsPriceDays.setId(StringUtil.getUUID());
                                                    mtHotelGoodsPriceDays.setMtHotelId(String.valueOf(mtHotelGoodsPriceBaseVo.getHotelId()));
                                                    mtHotelGoodsPriceDays.setMtGoodsId(String.valueOf(mtHotelGoodsPriceBaseVo.getGoodsId()));
                                                    mtHotelGoodsPriceDays.setMtSalePrice(priceDetail.getSalePrice());
                                                    mtHotelGoodsPriceDays.setMtSubPrice(priceDetail.getSubPrice());
                                                    mtHotelGoodsPriceDays.setMtSubRatio(priceDetail.getSubRatio());
                                                    mtHotelGoodsPriceDays.setMtDate(priceDetail.getDate());
                                                    mtHotelGoodsPriceDays.setMtDayType(priceDetail.getDayType());
                                                    mtHotelGoodsPriceDays.setCreateTime(new Date());
                                                    mtHotelGoodsPriceDays.setModifyTime(mtHotelGoodsPriceDays.getCreateTime());
                                                    mtHotelGoodsPriceDays.setState(0);
                                                    int s = mtHotelGoodsPriceDaysMapper.insert(mtHotelGoodsPriceDays);
                                                    redisTemplate.opsForValue().set("pullTodayGoodsPriceAboutCompareHotel_data_"+mtHotelGoodsPriceBaseVo.getHotelId()+"_"+startDate,"1",12, TimeUnit.HOURS);
                                                    thisAllMap.remove(String.valueOf(mtHotelGoodsPriceBaseVo.getHotelId()));
                                                    log.info("获取所有有效的未创建子酒店的酒店数据 存在小于等于25000分的酒店产品,不再校验该酒店其他产品直接存入表："+mtHotelGoodsPriceBaseVo.getHotelId()+"_"+mtHotelGoodsPriceBaseVo.getGoodsId());
                                                    break;
                                                }
                                            }
                                        }
                                        if(null != thisAllMap && thisAllMap.size()>0){
                                            for (Map.Entry h:thisAllMap.entrySet()){
                                                MtHotelGoodsPriceDaysError mtHotelGoodsPriceDaysError = new MtHotelGoodsPriceDaysError();
                                                mtHotelGoodsPriceDaysError.setId(StringUtil.getUUID());
                                                mtHotelGoodsPriceDaysError.setMtHotelId((String)h.getKey());
                                                mtHotelGoodsPriceDaysError.setMtDate(startDate);
                                                mtHotelGoodsPriceDaysError.setCreateTime(new Date());
                                                mtHotelGoodsPriceDaysError.setModifyTime(mtHotelGoodsPriceDaysError.getCreateTime());
                                                mtHotelGoodsPriceDaysError.setState(0);
                                                int s = mtHotelGoodsPriceDaysErrorMapper.insert(mtHotelGoodsPriceDaysError);
                                                redisTemplate.opsForValue().set("pullTodayGoodsPriceAboutCompareHotel_no_data_"+h.getKey()+"_"+startDate,"1",60, TimeUnit.SECONDS);
                                            }
                                            log.info("获取所有有效的未创建子酒店的酒店数据 pullTodayGoodsPriceAboutCompareHotel  存在不符合的酒店:{}", JSON.toJSONString(thisAllMap));
                                        }
                                    }else{
                                        log.info("获取所有有效的未创建子酒店的酒店数据 pullTodayGoodsPriceAboutCompareHotel  goodsPrices:{}，当前该批次酒店查询价格日历接口 goodsPrices为空:{}", JSON.toJSONString(hotelIdData), JSON.toJSONString(goodsPriceResult));
                                    }
                                }else{
                                    log.info("获取所有有效的未创建子酒店的酒店数据 pullTodayGoodsPriceAboutCompareHotel  goodsPriceResult:{}，当前该批次酒店查询价格日历接口 返回data为空:{}", JSON.toJSONString(hotelIdData), JSON.toJSONString(goodsPriceResult));
                                }

                            }else{
                                log.info("获取所有有效的未创建子酒店的酒店数据 pullTodayGoodsPriceAboutCompareHotel  hotelIdData:{}，当前该批次酒店查询价格日历接口失败:{}", JSON.toJSONString(hotelIdData), JSON.toJSONString(goodsPriceResult));
                                try {
                                    Thread.sleep(15000);
                                } catch (Exception e) {
                                    log.error(e.getMessage(), e);
                                }
                            }

                            hotelIdData = new ArrayList<>();


                            try {
                                Thread.sleep(500);//差不多一个小时跑完3万个酒店  每10个需要500毫秒，停500毫秒则每十个需要约1秒
                            } catch (Exception e) {
                                log.error(e.getMessage(), e);
                            }

                            /*if(i%1200==0){//10个酒店一次
                                try {
                                    Thread.sleep(900);//差不多一个小时跑完3万个酒店
                                } catch (Exception e) {
                                    log.error(e.getMessage(), e);
                                }
                                log.info("获取所有有效的未创建子酒店的酒店数据 sleep");
                            }*/

                        }
                    }
                }
            }
//////////////////MTAPIERROR///////////////////酒店产品价格接口数据异常：{"code":1000,"message":"参数非法:查询产品价格日历接口一分钟内的请求限额为80次, partnerBizId:3"}，，"{\"hotelIds\":[175234115,2267569,98128862,4674338,4935320,169140060,173399826,41390950,52867956,6884164],\"endDate\":\"2020-08-25\",\"startDate\":\"2020-08-24\"}"
        }else{
            log.info("获取所有有效的未创建子酒店的酒店数据 pullTodayGoodsPriceAboutCompareHotel  获取对比酒店数据失败{}，hotelUrl={}", JSON.toJSONString(hotelResponse),hotelUrl);

        }

        return null;
    }


    public Result<Object> getMtGoodsByHotelIdForJob(MtHotelGoodsSpecParamVo mtHotelGoodsSpecParamVo) {
        log.info("findMtGoodsCheckUpDown getMtGoodsByHotelIdForJob: "+ GsonUtils.GsonString(mtHotelGoodsSpecParamVo));
        Result<Object> apiResult = null;
        try{
            //为空默认全日房
            mtHotelGoodsSpecParamVo.setGoodsType(MtGoodsEnums.roomDateTypeEnum.DAY.getCode());
            if(StringUtils.isEmpty(mtHotelGoodsSpecParamVo.getCheckinDate())
                    && StringUtils.isEmpty(mtHotelGoodsSpecParamVo.getCheckoutDate())){
                mtHotelGoodsSpecParamVo.setCheckinDate(DateUtil.formatDate(new Date(),"yyyy-MM-dd"));
                mtHotelGoodsSpecParamVo.setCheckoutDate(DateUtil.formatDate(DateUtil.addDay(new Date(),30),"yyyy-MM-dd"));
            }

            List<Long> hotelList = new ArrayList<>();
            hotelList.add(mtHotelGoodsSpecParamVo.getHotelId());
            apiResult = this.getMtHotelGoods(null,hotelList,mtHotelGoodsSpecParamVo.getCheckinDate(),mtHotelGoodsSpecParamVo.getCheckoutDate(),mtHotelGoodsSpecParamVo.getGoodsType());
            if(apiResult.getCode()==CommonConstants.SUCCESS){
                return new Result<>(apiResult.getData());
            }
        }catch (Exception e){
            log.error("findMtGoodsCheckUpDown getMtGoodsByHotelIdForJob 异常："+e.getMessage()+",apiResult="+GsonUtils.GsonString(apiResult));
            apiResult = new Result<>("error:"+e.getMessage());
            e.printStackTrace();
        }
        return apiResult;
    }

    /**
     * 单独接口，校验酒店的指定产品，是否失效，一次最多二十家酒店。（只是查询产品进行校验没有对查询到的产品数据进行保存（保存动作都交给定时器每天一次更新保存，一次更新保存就会将失效和新增数据都更新到数据库表））
     * @param mtHotelGoodsCheckFailVo
     * @return
     */
    @Override
    public Result checkTenHotelsGoodsFailure(MtHotelGoodsCheckFailVo mtHotelGoodsCheckFailVo){
        List<MtHotelGoodsCheckFailOneVo> isFailHotelOneArrayReturn = new ArrayList<>();

        List<Long> swHotelIdsArray = new ArrayList<>();//所有酒店ids集合
        Map<String,Map<String,String>> swTenHotelGoodsMap = new HashMap<>();// [key = 酒店id , value = 产品id集合map（key=goodis,value=goodsid）]
        if(null != mtHotelGoodsCheckFailVo && null != mtHotelGoodsCheckFailVo.getHotels() && mtHotelGoodsCheckFailVo.getHotels().size()>0){
            //内部构建数据填充 swHotelIdsArray swTenHotelGoodsMap  不涉及调用接口
            buildFrontTenHotelDataVo(mtHotelGoodsCheckFailVo,swHotelIdsArray,swTenHotelGoodsMap);
        }

        //遍历酒店查询缓存是否有room数据，没有再进行接口的查询
        List<Long> needQueryRoomHotelIds = new ArrayList<>();
        Map<String,List<MtHotelRealRoomVo>> oneHotelRoomInfosDataArray = new HashMap<>();
        /*if(null != redisService.get("sw_mt_roominfo_by_hotelId")){
            try{
                oneHotelRoomInfosDataArray  = GsonUtils.GsonToMaps((String)redisService.get("sw_mt_roominfo_by_hotelId"));
            }catch (Exception e){
                e.printStackTrace();
            }
        }*/
        if(null == oneHotelRoomInfosDataArray || oneHotelRoomInfosDataArray.size()==0){
            Result manyHotelsRoomInfosResult = mtHotelRoomNameService.getMtHotelRoom(needQueryRoomHotelIds);
            oneHotelRoomInfosDataArray = (Map<String,List<MtHotelRealRoomVo>>)manyHotelsRoomInfosResult.getData();
            if(null == oneHotelRoomInfosDataArray){
                oneHotelRoomInfosDataArray = new HashMap<>();
            }
        }
        //查询酒店详情
        Map<String,MtHotelDetailVo> hotelsMap = new HashMap<>();
        List<MtHotelDetailVo> hotelDetailArray = mtHotelRoomNameService.returnHotelDetailRoomList(swHotelIdsArray);
        if(null != hotelDetailArray && hotelDetailArray.size()>0){
            for (MtHotelDetailVo h:hotelDetailArray){
                hotelsMap.put(String.valueOf(h.getBaseInfo().getHotelId()),h);
            }
        }

        if(null != swHotelIdsArray && swHotelIdsArray.size()>0 && null != oneHotelRoomInfosDataArray && oneHotelRoomInfosDataArray.size()>0){
            Result mtGoodsResult = null;
            Map apiReturnHotelMap = new HashMap();//如果酒店是失效的，则这个酒店接口不返回该酒店数，
            try{
                log.info("checkHotelGoodsFail查询的酒店 swHotelIdsArray={}",GsonUtils.GsonString(swHotelIdsArray));
                mtGoodsResult = getTendHotelGoodsInfoForJob(swHotelIdsArray);//如果酒店是失效的，则这个酒店接口不返回该酒店数，
                MtHotelGoodsVo mtHotelGoodsVo = null;
                if(null != mtGoodsResult.getData()){
                    mtHotelGoodsVo = GsonUtils.objToBean(mtGoodsResult.getData(),MtHotelGoodsVo.class);
                }
                if(null != mtHotelGoodsVo && mtHotelGoodsVo.getHotelGoods().size()>0){

                    log.info(" checkHotelGoodsFail 查询所有酒店后，接口返回size={}",mtHotelGoodsVo.getHotelGoods().size());
                    List<MtHotelGoodsChildInfoVo> newMtHotelGoods = mtHotelGoodsVo.getHotelGoods();
                    //比对 携程上架产品  是否在 在最新的产品里（美团接口根据时间段查询产品信息默认查询未来30天）
                    for (MtHotelGoodsChildInfoVo oneHotel:newMtHotelGoods){
                        String thisMtHotelId = String.valueOf(oneHotel.getHotelId());
                        if(null == oneHotelRoomInfosDataArray.get(thisMtHotelId)){
                            continue;
                        }
                        if(null == hotelsMap.get(thisMtHotelId)){
                            continue;
                        }
                        MtHotelDetailVo hotelDetail = hotelsMap.get(thisMtHotelId);
                        List<MtHotelRealRoomVo> oneHotelRoomInfos = oneHotelRoomInfosDataArray.get(thisMtHotelId);

                        Map<String, MtHotelGoodsBaseInfoVo> newOneHotelOneGoodsMap = new HashMap<>();
                        Map<String,String> newThisHotelGoodsRoomInfoMap = new HashMap<>();
                        List<MtHotelGoodsBaseInfoVo> newMtOneHotelgoodsData = oneHotel.getGoods();

                        apiReturnHotelMap.put(thisMtHotelId,thisMtHotelId);

                        if(null != newMtOneHotelgoodsData && newMtOneHotelgoodsData.size()>0){
                            //遍历这家酒店的所有最新产品

                            //checkThisHotelGoodsInfo 判断数据哪些是我们需要的产品 全日房
                            checkThisHotelGoodsInfo(hotelDetail,oneHotelRoomInfos,newMtOneHotelgoodsData,thisMtHotelId,newThisHotelGoodsRoomInfoMap,newOneHotelOneGoodsMap);

                            log.info(" checkHotelGoodsFail newThisHotelGoodsRoomInfoMap.size()={} ",newThisHotelGoodsRoomInfoMap.size());
                            if(newThisHotelGoodsRoomInfoMap.size()>0){
                                //1、校验携程上架产品，是否存在失效
                                MtHotelGoodsCheckFailOneVo ontHotelFailVo = new MtHotelGoodsCheckFailOneVo();
                                ontHotelFailVo.setMtHotelId(thisMtHotelId);
                                List<String> thisHotelAllGoodsFaiArray = new ArrayList<>();
                                //遍历携程上架酒店产品
                                Map<String,String> thisOneSwHotelGoodsMap = swTenHotelGoodsMap.get(thisMtHotelId);
                                for (Map.Entry switchsGoods:thisOneSwHotelGoodsMap.entrySet()){
                                    String goodsId = (String) switchsGoods.getKey();
                                    if(null == newThisHotelGoodsRoomInfoMap.get(goodsId)){
                                        log.info("checkHotelGoodsFail 符合为失效产品 hotelId={},newGoodsId={}",thisMtHotelId,goodsId);
                                        //为空，美团已下线该产品
                                        String roomId = (String)switchsGoods.getValue();

                                        thisHotelAllGoodsFaiArray.add(goodsId);

                                        insertProductDownLog(thisMtHotelId,roomId,goodsId,"2");

                                    }
                                }
                                if(null != thisHotelAllGoodsFaiArray && thisHotelAllGoodsFaiArray.size()>0){
                                    ontHotelFailVo.setGoodsIds(thisHotelAllGoodsFaiArray);
                                    isFailHotelOneArrayReturn.add(ontHotelFailVo);
                                    log.info(" checkHotelGoodsFail 当前酒店发现失效产品 goods={},hotelid={}",GsonUtils.GsonString(thisHotelAllGoodsFaiArray),thisMtHotelId);
                                }

                            }else{
                                log.error("checkHotelGoodsFail  异常   美团api未查询到酒店 全日房产品：mtHotelId={},",thisMtHotelId);

                                //该酒店有返回产品数据，但是没有全日房产品，则当前上架产品全部下架，我们只上架全日房产品
                                MtHotelGoodsCheckFailOneVo mtHotelGoodsCheckFailOneVo = buildOneHotelNoneGoodsQueueVo(swTenHotelGoodsMap,thisMtHotelId);
                                if(null != mtHotelGoodsCheckFailOneVo){
                                    isFailHotelOneArrayReturn.add(mtHotelGoodsCheckFailOneVo);
                                }
                            }

                        }else{
                            //....

                        }
                        log.info(" checkHotelGoodsFail  "+DateUtil.getCurrTime()+" 一家酒店结束：thisMtHotelId={}",thisMtHotelId);
                    }

                    //校验是否有酒店 没有产品返回，则都为失效（该酒店可能是下线了）
                    for(Map.Entry sw:swTenHotelGoodsMap.entrySet()){
                        String swHotelId = (String)sw.getKey();
                        if(null == apiReturnHotelMap.get(swHotelId)){
                            //不存在在最新美团接口返回的酒店里，说明可能下线了，其所有产品都要下架失效
                            log.info("checkHotelGoodsFail    该酒店产品信息为空：thisMtHotelId={},mtGoodsResult={}",swHotelId,GsonUtils.GsonString(mtGoodsResult));

                            //该酒店查无产品即该酒店所有产品已失效
                            MtHotelGoodsCheckFailOneVo mtHotelGoodsCheckFailOneVo = buildOneHotelNoneGoodsQueueVo(swTenHotelGoodsMap,swHotelId);
                            if(null != mtHotelGoodsCheckFailOneVo){
                                isFailHotelOneArrayReturn.add(mtHotelGoodsCheckFailOneVo);
                            }

                        }
                    }

                }else{
                    log.error("checkHotelGoodsFail 接口异常，酒店查询没有返回产品信息",GsonUtils.GsonString(mtHotelGoodsCheckFailVo));
                    return new Result("接口异常无信息返回:"+GsonUtils.GsonString(mtHotelGoodsVo),CommonConstants.REQUEST_ERROR);
                }
            }catch (Exception e){
                log.error("checkHotelGoodsFail 99  msg={},mtHotelGoodsCheckFailVo={}",e.getMessage(),GsonUtils.GsonString(mtHotelGoodsCheckFailVo));
                e.printStackTrace();
                return new Result("异常catch:"+e.getMessage(),CommonConstants.REQUEST_ERROR);
            }
        }
        if(null == isFailHotelOneArrayReturn){
            return new Result();
        }
        return new Result(GsonUtils.GsonString(isFailHotelOneArrayReturn),"success");
    }

    @Override
    public Result getMtHotelGoodsFindActivity(Object o, List<Long> hotelIds, String checkinDate, String checkoutDate, Integer goodsType) {
        //业务参数
        String data = "";
        Map<String,Object> dataMap = new HashMap<>();
        dataMap.put("hotelIds",hotelIds);
        dataMap.put("checkinDate",checkinDate);
        dataMap.put("checkoutDate",checkoutDate);
        dataMap.put("goodsType",goodsType);
        data = JSON.toJSONString(dataMap);
        //发起请求
        String response = MtUtils.createParamsPost(data, MtHotelEnums.apiMethodEnum.METHOD_HOTEL_GOODS.getMethod(),meituanSaveApiLogTask);
        //处理响应数据
        JSONObject responseJson = JSON.parseObject(response);
        if("0".equals(String.valueOf(responseJson.get("code")))) {
            //上游返回code=0，不管result内容是不是为空，都不能返回为异常，算正常
            String result = responseJson.getString("result");
            if (null != result) {
                MtHotelGoodsVo mtHotelGoodsVo = null;
                try{
                    mtHotelGoodsVo = JSON.parseObject(result,MtHotelGoodsVo.class);
                }catch (Exception e){
                    log.error("//////////////////产品信息解析对象异常："+ JSON.toJSONString(response));
                    log.error(e.getMessage(),e);
                    return new Result<>("parse error",CommonConstants.REQUEST_ERROR);
                }
                if(null != mtHotelGoodsVo && null != mtHotelGoodsVo.getHotelGoods() && mtHotelGoodsVo.getHotelGoods().size()>0){
                    return new Result<>(mtHotelGoodsVo);
                }else{
                    return new Result<>();
                }
            }else{
                log.info("////////////////MTAPIERROR///////////////////酒店产品列表接口数据异常 result is null hotelIds={}",GsonUtils.GsonString(hotelIds));
                return new Result<>(response,CommonConstants.SUCCESS);
            }
        }else{
            return new Result<>(responseJson.getString("message"), CommonConstants.REQUEST_ERROR);
        }
    }

    /**
     * 爬虫需要：返回有活动的产品  并保存在库表中
     * @param hotelIds
     * @param mtHotelGoodsVo
     */
    @Override
    public void checkFindActivity(Object hotelIds, MtHotelGoodsVo mtHotelGoodsVo) {
        if(null != mtHotelGoodsVo){
            //业务处理，保存数据
            List<MtHotelGoodsChildInfoVo> hotelGoods = mtHotelGoodsVo.getHotelGoods();
            List<MtHotelActiveInfo> mtHotelActiveInfoList = new ArrayList<>();
            List<Long> hotelIdsList = (List<Long>) hotelIds;
            int goodsCount = 0;
            int notGoodsCount = 0;
            if(null != hotelGoods && hotelGoods.size()>0){//多个酒店则数组大于1
                for(MtHotelGoodsChildInfoVo hotelGoodsVo:hotelGoods){
                    //遍历酒店产品信息
                    Integer hotelId = hotelGoodsVo.getHotelId();
                    Integer has = 0;
                    List<MtHotelGoodsBaseInfoVo> goods = hotelGoodsVo.getGoods();
                    if(null != goods && goods.size()>0){
                        //多家酒店，最多查询10家；每家酒店可能存在多个产品；
                        for (int i = 0; i <goods.size(); i++) {
                            MtHotelGoodsBaseInfoVo goodsBaseInfoVo = goods.get(i);
                            Iterator it = hotelIdsList.iterator();
                            while (it.hasNext()){
                                Object id = it.next();
                                if (String.valueOf(id).equals(goodsBaseInfoVo.getHotelId())){
                                    it.remove(); // 注意这里
                                    log.info("hotelIdsList中移除hotelId:{}!!",id);
                                }
                            }
                            Map<String,Integer> ac = goodsBaseInfoVo.getGoodsActivityMap();
                            if(null != ac && ac.size()>0){
                                MtHotelActiveInfo mtHotelActiveInfo = new MtHotelActiveInfo();
                                for (Map.Entry<String,Integer> m:ac.entrySet()){
                                    if(m.getValue()==1){
                                        //存在有效活动
                                        mtHotelActiveInfo.setIsActivityTags(1);
                                        has = 1;
                                        break;
                                    }
                                }
                                if(has==1){
                                    mtHotelActiveInfo.setId(String.valueOf(hotelId).substring(0,2)+goodsBaseInfoVo.getGoodsId().substring(0,2)+StringUtil.getUUID());
                                    mtHotelActiveInfo.setMtHotelId(String.valueOf(hotelId));
                                    mtHotelActiveInfo.setCreateTime(new Date());
//                                    mtHotelActiveInfoMapper.insert(mtHotelActiveInfo);
                                    mtHotelActiveInfoList.add(mtHotelActiveInfo);
                                    goodsCount++;
                                }
                            }
                            if(has==1){
                                break;
                            }
                            if(i == goods.size()-1){
                                if(has==0){
                                    MtHotelActiveInfo mtHotelActiveInfo = new MtHotelActiveInfo();
                                    mtHotelActiveInfo.setIsActivityTags(0);
                                    mtHotelActiveInfo.setId(String.valueOf(hotelId).substring(0,2)+goodsBaseInfoVo.getGoodsId().substring(0,2)+StringUtil.getUUID());
                                    mtHotelActiveInfo.setMtHotelId(String.valueOf(hotelId));
                                    mtHotelActiveInfo.setCreateTime(new Date());
//                                    mtHotelActiveInfoMapper.insert(mtHotelActiveInfo);
                                    mtHotelActiveInfoList.add(mtHotelActiveInfo);
                                    notGoodsCount++;
                                }
                            }
                        }
                    }
                }

                if(mtHotelActiveInfoList.size()>0){
                    int insInt = mtHotelActiveInfoMapper.insertList(mtHotelActiveInfoList);
                    log.info(">>>>>>>>>>>>批量新增{}条记录：有活动{}条；没有活动{}条!!",insInt,goodsCount,notGoodsCount);

                    final List<MtHotelActiveInfo> mtHotelActiveInfoListNotGoods = new ArrayList<>();
                    hotelIdsList.forEach(hotelIdNotGoods -> {
                        MtHotelActiveInfo mtHotelActiveInfo = new MtHotelActiveInfo();
                        mtHotelActiveInfo.setIsActivityTags(2);//不存在商品酒店
                        mtHotelActiveInfo.setId(String.valueOf(hotelIdNotGoods).substring(0,2)+"57"+ StringUtil.getUUID());
                        mtHotelActiveInfo.setMtHotelId(String.valueOf(hotelIdNotGoods));
                        mtHotelActiveInfo.setCreateTime(new Date());
                        mtHotelActiveInfoListNotGoods.add(mtHotelActiveInfo);
                    });

                    if(mtHotelActiveInfoListNotGoods.size()>0){
                        int insIntNotGoods = mtHotelActiveInfoMapper.insertList(mtHotelActiveInfoListNotGoods);
                        log.info(">>>>>>>>>>>>【没有产品酒店信息】批量新增{}条记录!!",insIntNotGoods);
                    }
                }
            }else{
                log.info("////////////////MTAPIERROR///////////////////酒店产品列表接口数据异常 hotelGoods is null");
            }
        }else{
            log.error("////////////////MTAPIERROR///////////////////酒店产品列表接口数据异常 mtHotelGoodsVo is null");
        }
    }


    /**
     * 返回给携程没有活动的酒店列表
     * @param o
     * @param mtHotelGoodsVo
     * @return list
     */
    @Override
    public Result<Object> checkFindNoActivity(Object o, MtHotelGoodsVo mtHotelGoodsVo,Map<String, String> map) {
        List<String> switchsHotelIds = new ArrayList<>();
        if(null != mtHotelGoodsVo){
            //业务处理，保存数据
            List<MtHotelGoodsChildInfoVo> hotelGoods = mtHotelGoodsVo.getHotelGoods();

            if(null != hotelGoods && hotelGoods.size()>0){//多个酒店则数组大于1
                for(MtHotelGoodsChildInfoVo hotelGoodsVo:hotelGoods){
                    //遍历酒店产品信息
                    String mtHotelId = String.valueOf(hotelGoodsVo.getHotelId());
                    Integer has = 0;
                    List<MtHotelGoodsBaseInfoVo> goods = hotelGoodsVo.getGoods();
                    if(null != goods && goods.size()>0){
                        //多家酒店，最多查询10家；每家酒店可能存在多个产品；
                        for (int i = 0; i <goods.size(); i++) {
                            MtHotelGoodsBaseInfoVo goodsBaseInfoVo = goods.get(i);
                            Map<String,Integer> ac = goodsBaseInfoVo.getGoodsActivityMap();
                            if(null != ac && ac.size()>0){
                                for (Map.Entry<String,Integer> m:ac.entrySet()){
                                    if(m.getValue()==1){
                                        //存在有效活动
                                        has = 1;
                                        break;
                                    }
                                }
                            }
                            if(has==1){
                                break;
                            }
                        }
                        //如果不存在活动产品酒店
                        if(has == 0){
                            for(Map.Entry<String, String> entry : map.entrySet()){
                                String switchHotelId = entry.getKey();
                                String meituanHotelId = entry.getValue();
                                if(mtHotelId.equals(meituanHotelId)){
                                    switchsHotelIds.add(switchHotelId);
                                }
                            }
                        }
                    }
                }
            }else{
                log.info("////////////////MTAPIERROR///////////////////酒店产品列表接口数据异常 hotelGoods is null");
            }
        }else{
            log.error("////////////////MTAPIERROR///////////////////酒店产品列表接口数据异常 mtHotelGoodsVo is null");
        }

        Result<Object> result = new Result<>();
        result.setCode(CommonConstants.SUCCESS);
        result.setMsg("查询成功");
        result.setData(JacksonUtil.objectToJson(switchsHotelIds));
        return result;
    }

    public static void main(String[] args) {
//        String now0 = DateUtil.getCurrStrAdd(-2,"yyyy-MM-dd");
//        String now1 = DateUtil.getCurrStrAdd(-3,"yyyy-MM-dd");
//        String now2 = DateUtil.getCurrStrAdd(-4,"yyyy-MM-dd");
//
//        String s = DateUtil.dayForWeek("2021-01-29");
//        System.out.printf("ssss="+s);
//
//        String now  = DateUtil.getCurrTimeYmd("dd")+DateUtil.getCurrTimeYmd("HH");
//        System.out.printf(""+now+" "+now1+"  "+now2);

        Map<String,String> queryDate = new HashMap<>();
        int j = 1;
        while (true){
            if(queryDate.size()==3){
                break;
            }else{
                if(j!=1){
                    String nextDate = DateUtil.getCurrStrAdd(-j,"yyyy-MM-dd");
                    String week = DateUtil.dayForWeek(nextDate);
                    if(!week.equals("周六") && !week.equals("周日")){
                        queryDate.put(nextDate.replace("-",""),week);
                    }
                }
            }
            j++;
        }
        System.out.printf("queryDate="+GsonUtils.GsonString(queryDate));
        Map<String,String> map = new HashMap<>();
        int index = 1;
        for (Map.Entry m:queryDate.entrySet()){
            map.put("notifyPriceDate"+index,(String)m.getKey());
            index++;
        }
        System.out.printf("map="+GsonUtils.GsonString(map));
    }
    @Override
    public void statMtGoodsPriceLibraryCallback(String source) {
        //跳过昨天，前四天里的早先三天，防止昨天的一些产品是新上架的，统计出来的标准价不准确
        //跳过周六周日  价格偏高


        List<MtHotelGoodsPriceLibrary> list = new ArrayList<>();
        Map<String,String> map = new HashMap<>();
/*
        if(!ObjectUtils.isEmpty(source) &&  "week".equals(source)){//该方法暂时不会进来，主动查询和异步通知push队列代码已注释

            String paramHotels = "";
            Long size = redisService.queueSize("swmt_queue_update_library_pirce_this_week");
            if(size>0){
                if(new BigDecimal(200).compareTo(new BigDecimal(size))<0){
                    log.info("Mt Cb Goods Price Library This Week Job 重新查询本周标准价存在size大于200={}",size);
                    size = 200L;
                }

                log.info("Mt Cb Goods Price Library This Week Job 重新查询本周标准价存在size={}",size);
                for (int i = 0; i < size; i++) {
                    String hotelId = (String)redisService.RPop("swmt_queue_update_library_pirce_this_week");
                    if(!ObjectUtils.isEmpty(hotelId)){
                        redisService.setUnit("swmt_queue_update_library_pirce_this_week_has"+hotelId,1,4L,TimeUnit.HOURS);
                        paramHotels += "'"+hotelId+"'"+",";
                    }else{
                        log.info("Mt Cb Goods Price Library This Week Job 重新查询本周标准价获取酒店为空，break");
                        break;
                    }
                }
                //查询本周今天前一天  会进来的只会是周二三四五
                String yesday = DateUtil.getCurrStrAdd(-1,"yyyy-MM-dd");
                map.put("notifyPriceDate1",yesday.replace("-",""));
                map.put("hotelIds",paramHotels.substring(0,paramHotels.length()-1));
                log.info("source={},statMtGoodsPriceLibraryCallback 针对指定酒店查询本周今天前一天标准价参数map={}",source,GsonUtils.GsonString(map));
                SendUtils.dingMsgNotLog("[WEEK-STAT-LIBRARY-PRICE]针对指定酒店统计本周今天前一天标准价 ",DateUtil.getCurrTime()+" map="+GsonUtils.GsonString(map),MessageEnums.genre.GOODS_STATUS_AND_PRICE.getCode(),restTemplate);
                list = mtHotelGoodsPriceMapper.queryStatMtGoodsPriceLibraryCallbackThisWeek(map);//10万产品 3天(3张表) 1-2分钟
            }
        }else{

        }*/


        Integer queryDays = 2;
//        if(null != redisService.get("swmt_stat_price_days")){
//            queryDays = (Integer) redisService.get("swmt_stat_price_days");
//        }
        Map<String,String> queryDate = new HashMap<>();
        int j = 1;
        while (true){
            if(queryDate.size()==queryDays){
                break;
            }else{
                if(j!=1){//跳过昨天一天
                    String nextDate = DateUtil.getCurrStrAdd(-j,"yyyy-MM-dd");
                    String week = DateUtil.dayForWeek(nextDate);
                    if(!week.equals("周六") && !week.equals("周日")){
                        queryDate.put(nextDate.replace("-",""),week);//yyyyMMdd
                    }
                }
            }
            j++;
        }
        int index = 1;
        for (Map.Entry m:queryDate.entrySet()){
            map.put("notifyPriceDate"+index,(String)m.getKey());//yyyyMMdd
            index++;
        }
        log.info("source={},statMtGoodsPriceLibraryCallback 参数map={}",source,GsonUtils.GsonString(map));
        SendUtils.dingMsgNotLog("[STAT-LIBRARY-PRICE]即将开始统计标准价 ",DateUtil.getCurrTime()+" dateQuery="+GsonUtils.GsonString(map),MessageEnums.genre.GOODS_STATUS_AND_PRICE.getCode(),restTemplate);
        list = mtHotelGoodsPriceMapper.queryStatMtGoodsPriceLibraryCallback(map);//10万产品 3天(3张表) 1-2分钟
        if(!ObjectUtils.isEmpty(list)){
            Integer time = list.size()*10/1000/60;
            if(ObjectUtils.isEmpty(source)){
                SendUtils.dingMsgNotLog("[REDIS-SET-LIBRARY-PRICE]即将更新缓存标准价 ",DateUtil.getCurrTime()+" 预计耗时："+time+"分钟",MessageEnums.genre.GOODS_STATUS_AND_PRICE.getCode(),restTemplate);
            }
            log.info("source={},statMtGoodsPriceLibraryCallback 统计出的产品标准价：size={}",source,list.size());
            try {
                Thread.sleep(2000);
            } catch (Exception e2) {
                e2.printStackTrace();
            }
            //缓存标准价
            Integer isSaleNum = 0;
            Integer setSuccessNum = 0;
            Date date = new Date();
            String now  = DateUtil.getCurrTimeYmd("dd")+DateUtil.getCurrTimeYmd("HH");
            for (int i = 0; i < list.size(); i++) {
                if(null != redisService.get("statMtGoodsPriceLibraryCallback_stop")){
                    log.info("statMtGoodsPriceLibraryCallback 主动停止更新标准价缓存");
                    break;
                }
                MtHotelGoodsPriceLibrary p = list.get(i);
                p.setCreateTime(date);
                p.setId(p.getId()+now+StringUtil.getFourRandom());
                log.info("source={},statMtGoodsPriceLibraryCallback i={},p={}",source,i,GsonUtils.GsonString(p));
                try {
                    Thread.sleep(10);
                } catch (Exception e2) {
                    e2.printStackTrace();
                }
                String existSaleRg = (String)redisService.get(CommonConstants.RG_SET_LIBRARY_SELLING+p.getMtHotelId()+"_"+p.getMtGoodsId());
                if(ObjectUtils.isEmpty(existSaleRg)){
                    String existSale = null;
                    existSale = (String)redisService.hmGet(CommonConstants.SWITCH_SELLING_THE_HOUSE_TYPE,p.getMtHotelId()+"_"+p.getMtGoodsId());
                    if(!ObjectUtils.isEmpty(existSale)){
                        //log.info("statMtGoodsPriceLibraryCallback 进入第二版 判断上架产品：MtGoodsId={},existSale={}",p.getMtGoodsId(),existSale);
                    }else{
                        existSale = (String)redisService.get(CommonConstants.SWITCH_SELLING_THE_HOUSE_TYPE+p.getMtHotelId()+"_"+p.getMtGoodsId());
                        //log.info("statMtGoodsPriceLibraryCallback 进入第一版 判断上架产品：MtGoodsId={},existSale={}",p.getMtGoodsId(),existSale);
                    }
                    if(null != existSale){//携程上架产品
                        isSaleNum += 1;
                        Integer redisPrice = p.getPrice();
                        Integer redisPriceMin = 2000;
                        if(null != redisService.get("swmt_library_min_compare")){
                            redisPriceMin = (Integer)redisService.get("swmt_library_min_compare");
                        }
                        if(new BigDecimal(redisPrice).compareTo(new BigDecimal(redisPriceMin))<0){
                            redisPrice = redisPriceMin;
                        }
                        boolean setSuccess = redisService.setUnit(MeituanConstants.REDIS_ONE_GOODS_PRICE_LIBRARY_NEW+p.getMtHotelId()+"_"+p.getMtGoodsId(),redisPrice,3L,TimeUnit.DAYS);
                        if(setSuccess){
                            setSuccessNum +=1;
                        }else{
                            log.info("source={},statMtGoodsPriceLibraryCallback 更新缓存失败：{}",source,p.getMtHotelId()+"_"+p.getMtGoodsId());
                        }
                    }else{
                        log.info("source={},statMtGoodsPriceLibraryCallback 不是上架产品：{}",source,p.getMtHotelId()+"_"+p.getMtGoodsId());
                    }
                }else{
                    log.info("source={},statMtGoodsPriceLibraryCallback 该产品为人工设置标准价当前job不进行设置：{}",source,p.getMtHotelId()+"_"+p.getMtGoodsId());
                }

            }

            log.info("source={},statMtGoodsPriceLibraryCallback 统计更新标准价缓存结束：统计的数量={}，实际符合上架产品数量:{}，实际更新缓存成功数量：{}",source,list.size(),isSaleNum,setSuccessNum);
            SendUtils.dingMsgNotLog("[REDIS-FINISH-LIBRARY-PRICE]缓存标准价完成 ",DateUtil.getCurrTime()+" 统计的数量："+list.size()+" 实际符合上架产品数量："+isSaleNum+" 成功更新缓存数量："+setSuccessNum,MessageEnums.genre.GOODS_STATUS_AND_PRICE.getCode(),restTemplate);

            log.info("ssource={},tatMtGoodsPriceLibraryCallback 执行保存到数据库开始：insertList={}",source,list.size());
            try {
                mtHotelGoodsPriceLibraryMapper.insertList(list);
            }catch (Exception e){
                log.info("ssource={},tatMtGoodsPriceLibraryCallback mtHotelGoodsPriceLibraryMapper.insertList异常：{}",source,e.getMessage());
                e.printStackTrace();
            }
            log.info("source={},statMtGoodsPriceLibraryCallback 执行保存到数据库结束",source);
        }else{
            log.info("source={},statMtGoodsPriceLibraryCallback 统计产品标准价为空！map={}",source,GsonUtils.GsonString(map));
            SendUtils.dingMsgNotLog("[STAT-LIBRARY-PRICE]统计产品标准价数据为空，请核实 ",DateUtil.getCurrTime()+" 查询日期库表为："+GsonUtils.GsonString(map),MessageEnums.genre.GOODS_STATUS_AND_PRICE.getCode(),restTemplate);
        }
    }

    private void buildFrontTenHotelDataVo(MtHotelGoodsCheckFailVo mtHotelGoodsCheckFailVo,List<Long> swHotelIdsArray,Map<String,Map<String,String>> swTenHotelGoodsMap) {
        for (MtHotelGoodsCheckFailOneVo oneHotel:mtHotelGoodsCheckFailVo.getHotels()){
            Long thisHotelId = Long.valueOf(oneHotel.getMtHotelId());
            List<String> goodsIds = oneHotel.getGoodsIds();

            swHotelIdsArray.add(thisHotelId);

            if(null != goodsIds && goodsIds.size()>0){
                for (String g:goodsIds){
                    Map<String,String> thisSwHotelGoodsMap = swTenHotelGoodsMap.get(thisHotelId);
                    if(null == thisSwHotelGoodsMap || thisSwHotelGoodsMap.size()==0){
                        thisSwHotelGoodsMap = new HashMap<>();
                    }
                    thisSwHotelGoodsMap.put(g,g);
                    swTenHotelGoodsMap.put(oneHotel.getMtHotelId(),thisSwHotelGoodsMap);
                }
            }
        }
    }





    private void checkThisHotelGoodsInfo(MtHotelDetailVo hotelDetail,List<MtHotelRealRoomVo> oneHotelRoomInfos,List<MtHotelGoodsBaseInfoVo> newMtOneHotelgoodsData, String thisMtHotelId, Map<String,String> newThisHotelGoodsRoomInfoMap, Map<String,MtHotelGoodsBaseInfoVo> newOneHotelOneGoodsMap) {
        for (MtHotelGoodsBaseInfoVo newMtgoodsBaseInfoVo:newMtOneHotelgoodsData){
            if(newMtgoodsBaseInfoVo.getGoodsType()==1){
                //全日房
                List<MtHotelGoodsBaseRoomVo> goodsBaseRoom = newMtgoodsBaseInfoVo.getRoomInfoList();

                //log.info("/////////////////////////////  findMtGoodsCheckUpDown goodsBaseInfoVo.getRoomInfoList() :   {} ",GsonUtils.GsonString(goodsBaseRoom));
                if(null != goodsBaseRoom && goodsBaseRoom.size()>0){
                                       /* if(goodsBaseRoom.get(0).getRoomId().equals("79945175")){
                                            log.info("////////////////////");
                                        }*/
                    if(goodsBaseRoom.size()>1){
                        //上游标识每个产品只对应一个房间信息,但返回的是list，特殊处理
                        log.error("checkHotelGoodsFail ////////////////MTAPIERROR///////////////////酒店产品列表接口数据异常 goodsBaseRoom size >1");
                        //return new Result<>("goodsBaseRoom error overstep", CommonConstants.PARSE_ERROR);
                    }else{
                        String thisRealRoomId = "";
                        thisRealRoomId = mtHotelRoomNameService.goodsInfosCheckReturnGoodsRealRoomId(oneHotelRoomInfos,hotelDetail,thisMtHotelId,goodsBaseRoom,newMtgoodsBaseInfoVo.getGoodsId());
                        if(!ObjectUtil.isEmpty(thisRealRoomId)){
                            newMtgoodsBaseInfoVo.setRoomId(thisRealRoomId);
                        }else{
                            log.error("checkHotelGoodsFail ////////////////  error  异常，未找到产品的realRoomId，请人工核实！！！！！："+GsonUtils.GsonString(newMtgoodsBaseInfoVo));
                            newMtgoodsBaseInfoVo.setRoomId(goodsBaseRoom.get(0).getRoomId());
                        }
                    }
                    //额外字段
                    newMtgoodsBaseInfoVo.setMtCityId(goodsBaseRoom.get(0).getCityId());
                    newMtgoodsBaseInfoVo.setMtRoomName(goodsBaseRoom.get(0).getRoomName());
                }
                newThisHotelGoodsRoomInfoMap.put(newMtgoodsBaseInfoVo.getGoodsId(),newMtgoodsBaseInfoVo.getRoomId());
                newOneHotelOneGoodsMap.put(newMtgoodsBaseInfoVo.getHotelId()+"_"+newMtgoodsBaseInfoVo.getGoodsId(),newMtgoodsBaseInfoVo);

            }else{
                log.error("checkHotelGoodsFail   该产品非全日房跳过：thisMtHotelId={},getGoodsId={}",thisMtHotelId,newMtgoodsBaseInfoVo.getGoodsId());
            }
        }
    }

    private void insertProductDownLog(String thisMtHotelId,String roomId,String goodsId,String source) {
        MtHotelGoodsUpDownLog mtHotelGoodsUpDownLog = new MtHotelGoodsUpDownLog();
        mtHotelGoodsUpDownLog.setId(StringUtil.getUUID());
        mtHotelGoodsUpDownLog.setCreateTime(new Date());
        mtHotelGoodsUpDownLog.setMtHotelId(thisMtHotelId);
        mtHotelGoodsUpDownLog.setMtRoomId(roomId);
        mtHotelGoodsUpDownLog.setMtGoodsId(goodsId);
        mtHotelGoodsUpDownLog.setType("0");
        mtHotelGoodsUpDownLog.setSource(source);//1、所属酒店无返回任何产品 可能下线了 2、该酒店有产品但无该产品   3、该酒店有返回产品但是没有全日房产品，则目前该酒店上架产品都要下架，我们只上架全日房产品
        try {
            mtHotelGoodsUpDownLogMapper.insert(mtHotelGoodsUpDownLog);
        }catch (Exception e){
            log.error("checkHotelGoodsFail  mtHotelGoodsUpDownLogMapper保存失败 1183");
            e.printStackTrace();
        }
    }

    private MtHotelGoodsCheckFailOneVo buildOneHotelNoneGoodsQueueVo(Map<String,Map<String,String>> swTenHotelGoodsMap,String swHotelId) {
        MtHotelGoodsCheckFailOneVo mtHotelGoodsCheckFailOneVo = null;
        Map<String,String> thisOneSwHotelGoodsMap = swTenHotelGoodsMap.get(swHotelId);
        if(null != thisOneSwHotelGoodsMap && thisOneSwHotelGoodsMap.size()>0){
            mtHotelGoodsCheckFailOneVo = new MtHotelGoodsCheckFailOneVo();
            mtHotelGoodsCheckFailOneVo.setMtHotelId(swHotelId);
            List<String> thisHotelAllGoodsFaiArray = new ArrayList<>();
            for (Map.Entry gid:thisOneSwHotelGoodsMap.entrySet()){
                String goodsId = (String)gid.getKey();
                thisHotelAllGoodsFaiArray.add(goodsId);
                insertProductDownLog(swHotelId,null,goodsId,"1");
            }
            mtHotelGoodsCheckFailOneVo.setGoodsIds(thisHotelAllGoodsFaiArray);

        }
        return mtHotelGoodsCheckFailOneVo;
    }

/*    public Result<Object> getTendHotelGoodsInfoForJob(List<Long> hotelList) {
        Result<Object> apiResult = null;
        try{
            MtHotelGoodsSpecParamVo mtHotelGoodsSpecParamVo = new MtHotelGoodsSpecParamVo();
            mtHotelGoodsSpecParamVo.setGoodsType(MtGoodsEnums.roomDateTypeEnum.DAY.getCode());
            mtHotelGoodsSpecParamVo.setCheckinDate(DateUtil.formatDate(new Date(),"yyyy-MM-dd"));
            mtHotelGoodsSpecParamVo.setCheckoutDate(DateUtil.formatDate(DateUtil.addDay(new Date(),30),"yyyy-MM-dd"));
            apiResult = this.getMtHotelGoods(null,hotelList,mtHotelGoodsSpecParamVo.getCheckinDate(),mtHotelGoodsSpecParamVo.getCheckoutDate(),mtHotelGoodsSpecParamVo.getGoodsType());
            if(apiResult.getCode()==CommonConstants.SUCCESS){
                return new Result<>(apiResult.getData());
            }
        }catch (Exception e){
            log.error(" getMtGoodsByHotelIdForJob 异常："+e.getMessage()+",apiResult="+GsonUtils.GsonString(apiResult));
            apiResult = new Result<>("error:"+e.getMessage());
            e.printStackTrace();
        }
        return apiResult;
    }*/

    public void requestSwitchsModifyPricesAboutOneHotelGoodList(List<MtHotelGoodsPriceBaseDetailVo> thisGoodsPriceModelsChanges) {
        log.info("当前该售卖产品存在价格日历发送改变，推送携程修改价格，进入方法 requestSwitchsModifyPricesAboutOneHotelGoodList :{}",GsonUtils.GsonString(thisGoodsPriceModelsChanges));

        //ModifyPriceListVo switchsModifyPircesListVo = new ModifyPriceListVo();
        List<ModifyPriceVo> modifyPrices = new ArrayList<>();
        if(null != thisGoodsPriceModelsChanges && thisGoodsPriceModelsChanges.size()>0){
            for (MtHotelGoodsPriceBaseDetailVo vo:thisGoodsPriceModelsChanges){
                ModifyPriceVo switchsPriceVo = new ModifyPriceVo();
                switchsPriceVo.setMtGoodId(vo.getGoodsId());
                switchsPriceVo.setMtHotelId(vo.getHotelId());
                switchsPriceVo.setPrice(vo.getSalePrice());
                switchsPriceVo.setSubPrice(vo.getSubPrice());
                switchsPriceVo.setTime(vo.getDate());
                modifyPrices.add(switchsPriceVo);
            }

            //switchsModifyPircesListVo.setModifyPrices(modifyPrices);
            String host = CommonUrlConstants.SWITCHS_HOST;
            String batchUrl = host+ UrlMtEnums.mtDealNotifyGoods.MODIFY_PRICES_BATCH_ABOUT_HOTEL.getValue();//+"?access_token="+ HttpClientBaseAuth.getAuthToken()
            Map params = new HashMap();
            params.put("modifyPrices",modifyPrices);
            log.info("当前该售卖产品存在价格日历发送改变，推送携程修改价格，进入方法 requestSwitchsModifyPricesAboutOneHotelGoodList 请求参数 ： {}", JSON.toJSONString(params));
            //发起请求
            Result response = RestTemplateUtils.post(batchUrl, JSON.toJSONString(params),restTemplate);
            log.error("推送携程修改价格 requestSwitchsModifyPricesAboutOneHotelGoodList 返回 : {},{},{}",batchUrl, JSON.toJSONString(params), JSON.toJSONString(response));
            if(response.getCode() != CommonConstants.SUCCESS){

            }else{
            }

        }
    }

    @Override
    public Map<String,Object> saveCallbackGoodsRp(List<MtHotelGoodsCallbackVo> goods){
        if(null != goods && goods.size()>0){
            StringBuilder sb = new StringBuilder();
            List<MtHotelGoods> goodsEntityList = new ArrayList<>();
            List<MtHotelGoodsBreakfast> breakfastEntityDataSave = new ArrayList<>();
            List<MtHotelGoodsBookRule> bookRuleEntityDataSave = new ArrayList<>();
            List<MtHotelGoodsCancelRule> cancelRuleEntityDataSave = new ArrayList<>();
            Map<String,List<MtHotelGoodsPriceBaseDetailVo>> priceListMap = new HashMap<>();
            for (int i = 0; i < goods.size(); i++) {
                MtHotelGoodsCallbackVo vo = goods.get(i);
                String hotelId = vo.getHotelId();
                String goodsId = vo.getGoodsId();
                String goodsName = vo.getGoodsName();
                sb.append("'"+goodsId+"'");
                if(i!=goods.size()-1){
                    sb.append(",");
                }
                //遍历 一家酒店 - 所有产品
                MtHotelGoods goodsEntity = new MtHotelGoods();
                goodsEntity.setId(String.valueOf(UUID.randomUUID()));
                goodsEntity.setMtHotelId(hotelId);
                goodsEntity.setMtGoodsId(goodsId);
                goodsEntity.setMtGoodsName(goodsName);
                List<MtHotelGoodsBaseRoomVo> goodsBaseRoom = vo.getRoomInfoList();
                if(null != goodsBaseRoom && goodsBaseRoom.size()>0){
                    if(goodsBaseRoom.size()>1){
                        //上游标识每个产品只对应一个房间信息,但返回的是list，特殊处理
                        log.error("////////////////MTAPIERROR///////////////////saveCallbackGoodsRp数据异常 goodsBaseRoom size >1");
                        //return new Result<>("goodsBaseRoom error overstep", CommonConstants.PARSE_ERROR);
                    }else{
                        goodsEntity.setMtCityId(goodsBaseRoom.get(0).getCityId());
                        goodsEntity.setMtRoomName(goodsBaseRoom.get(0).getRoomName());
                        goodsEntity.setMtRoomId(goodsBaseRoom.get(0).getRoomId());
                    }
                }
                goodsEntity.setMtNeedRealTel(vo.getNeedRealTel());
                goodsEntity.setMtGoodsStatus(vo.getGoodsStatus());
                goodsEntity.setMtGoodsType(vo.getGoodsType());
                goodsEntity.setMtConfirmType(vo.getConfirmType());
                goodsEntity.setMtAveragePrice(vo.getAveragePrice());
                goodsEntity.setMtOriginalPrice(vo.getOriginalPrice());
                goodsEntity.setMtThirdParty(vo.getThirdParty());
                goodsEntity.setState(CommonEnums.STATE_NORMAL.getCode());
                goodsEntity.setRemark("");
                goodsEntity.setMtGoodsActivity(JSON.toJSONString(vo.getGoodsActivityMap()));
                goodsEntity.setCreateTime(DateUtil.getNowTime());
                goodsEntity.setModifyTime(DateUtil.getNowTime());
                goodsEntityList.add(goodsEntity);
                //每个产品对应有早餐信息
                List<MtHotelGoodsBreakfastVo> breakfastVoList = vo.getBreakFast();
                if(null != breakfastVoList && breakfastVoList.size()>0){
                    for (MtHotelGoodsBreakfastVo breakfastVo:breakfastVoList){
                        MtHotelGoodsBreakfast breakfastEntity = new MtHotelGoodsBreakfast();
                        breakfastEntity.setId(String.valueOf(UUID.randomUUID()));
                        breakfastEntity.setMtHotelId(goodsEntity.getMtHotelId());
                        breakfastEntity.setMtRoomId(goodsEntity.getMtRoomId());
                        breakfastEntity.setMtGoodsId(vo.getGoodsId());
                        breakfastEntity.setMtBreakfastType(breakfastVo.getBreakfastType());
                        breakfastEntity.setMtBreakfastNum(breakfastVo.getBreakfastNum());
                        breakfastEntity.setMtStartDate(String.valueOf(breakfastVo.getInStartDate()));
                        breakfastEntity.setMtEndDate(String.valueOf(breakfastVo.getInEndDate()));
                        breakfastEntity.setState(CommonEnums.STATE_NORMAL.getCode());
                        breakfastEntity.setRemark("");
                        breakfastEntity.setCreateTime(DateUtil.getNowTime());
                        breakfastEntity.setModifyTime(DateUtil.getNowTime());
                        breakfastEntityDataSave.add(breakfastEntity);
                    }
                }
                //每个产品对应预订规则信息
                List<MtHotelGoodsBookRuleVo> bookRuleVoList = vo.getBookRules();
                if(null != bookRuleVoList && bookRuleVoList.size()>0){
                    for (MtHotelGoodsBookRuleVo bookRuleVo:bookRuleVoList){
                        MtHotelGoodsBookRule bookRule = new MtHotelGoodsBookRule();
                        bookRule.setId(String.valueOf(UUID.randomUUID()));
                        bookRule.setMtHotelId(goodsEntity.getMtHotelId());
                        bookRule.setMtRoomId(goodsEntity.getMtRoomId());
                        bookRule.setMtGoodsId(goodsId);
                        bookRule.setMtSerialCheckinMin(bookRuleVo.getSerialCheckinMin());
                        bookRule.setMtSerialCheckinMax(bookRuleVo.getSerialCheckinMax());
                        bookRule.setMtRoomCountMin(bookRuleVo.getRoomCountMin());
                        bookRule.setMtRoomCountMax(bookRuleVo.getRoomCountMax());
                        bookRule.setMtEarliestBookingDays(bookRuleVo.getEarliestBookingDays());
                        bookRule.setMtEarliestBookingHours(bookRuleVo.getEarliestBookingHours());
                        bookRule.setMtLatestBookingDays(bookRuleVo.getLatestBookingDays());
                        bookRule.setMtLatestBookingHours(bookRuleVo.getLatestBookingHours());
                        bookRule.setMtIsDaybreakBooking(bookRuleVo.getIsDaybreakBooking());
                        bookRule.setMtInStartDate(bookRuleVo.getInStartDate());
                        bookRule.setMtInEndDate(bookRuleVo.getInEndDate());
                        bookRule.setState(CommonEnums.STATE_NORMAL.getCode());
                        bookRule.setRemark("");
                        bookRule.setCreateTime(DateUtil.getNowTime());
                        bookRule.setModifyTime(DateUtil.getNowTime());
                        bookRuleEntityDataSave.add(bookRule);
                    }
                }
                //每个产品对应取消规则信息
                List<MtHotelGoodsCancelRuleVo> cancelRulesVoList = vo.getCancelRules();
                if(null != cancelRulesVoList && cancelRulesVoList.size()>0){
                    for (MtHotelGoodsCancelRuleVo cancelVo:cancelRulesVoList){
                        MtHotelGoodsCancelRule cancelRule = new MtHotelGoodsCancelRule();
                        cancelRule.setId(String.valueOf(UUID.randomUUID()));
                        cancelRule.setMtHotelId(hotelId);
                        cancelRule.setMtRoomId(goodsEntity.getMtRoomId());
                        cancelRule.setMtGoodsId(goodsId);
                        cancelRule.setMtCancelType(cancelVo.getCancelType());
                        cancelRule.setMtAheadCancelDays(cancelVo.getAheadCancelDays());
                        cancelRule.setMtAheadCancelHours(cancelVo.getAheadCancelHours());
                        cancelRule.setMtDeductType(cancelVo.getDeductType());
                        cancelRule.setState(CommonEnums.STATE_NORMAL.getCode());
                        cancelRule.setRemark("");
                        cancelRule.setCreateTime(DateUtil.getNowTime());
                        cancelRule.setModifyTime(DateUtil.getNowTime());
                        cancelRuleEntityDataSave.add(cancelRule);
                    }
                }
                //商品价格信息保存
                List<MtHotelGoodsPriceBaseDetailVo> priceModels = vo.getPriceModels();
                priceListMap.put(hotelId+","+goodsId,priceModels);
            }

            saveGoodsPriceInfosGroup(priceListMap);

            Map returnMap = new HashMap();
            if(null != goodsEntityList && goodsEntityList.size()>0){
                //旧数据删除，插入新数据
                Map map = new HashMap();
                map.put("ids",sb.toString());
                int GoDel = mtHotelGoodsMapper.deleteBatchByGoodsIds(map);
                if(GoDel !=-1){
                    mtHotelGoodsMapper.insertList(goodsEntityList);
                }
                returnMap.put("goodsEntityList",goodsEntityList);
            }
            if(null != breakfastEntityDataSave && breakfastEntityDataSave.size()>0){
                Map map = new HashMap();
                map.put("ids",sb.toString());
                int brDel = mtHotelGoodsBreakfastMapper.deleteBatchByGoodsIds(map);
                if(brDel !=-1){
                    mtHotelGoodsBreakfastMapper.insertList(breakfastEntityDataSave);
                }
                returnMap.put("breakfastEntityDataSave",breakfastEntityDataSave);
            }
            if(null != cancelRuleEntityDataSave && cancelRuleEntityDataSave.size()>0){
                Map map = new HashMap();
                map.put("ids",sb.toString());
                int canDel = mtHotelGoodsCancelRuleMapper.deleteBatchByGoodsIds(map);
                if(canDel !=-1){
                    mtHotelGoodsCancelRuleMapper.insertList(cancelRuleEntityDataSave);
                }
                returnMap.put("cancelRuleEntityDataSave",cancelRuleEntityDataSave);
            }
            if(null != bookRuleEntityDataSave && bookRuleEntityDataSave.size()>0){
                Map map = new HashMap();
                map.put("ids",sb.toString());
                int boDel = mtHotelGoodsBookRuleMapper.deleteBatchByGoodsIds(map);
                if(boDel!=-1){
                    mtHotelGoodsBookRuleMapper.insertList(bookRuleEntityDataSave);
                }
                returnMap.put("bookRuleEntityDataSave",bookRuleEntityDataSave);
            }
            return returnMap;
        }
        return null;
    }

    /**
     * 内部接口，产品各项信息规则总结返回,接口限制为一个hotelId
     * 返回数据类型：map<key=房型id,value=mtHotelGoodsDto>
     * @param mtHotelGoodsSpecParamVo
     * @return
     */
    @Override
    public Result<Object> getMtGoodsByHotelId(MtHotelGoodsSpecParamVo mtHotelGoodsSpecParamVo) {
        List<Long> hotelList = new ArrayList<>();
        hotelList.add(mtHotelGoodsSpecParamVo.getHotelId());
        if(StringUtils.isEmpty(mtHotelGoodsSpecParamVo.getCheckinDate())
                && StringUtils.isEmpty(mtHotelGoodsSpecParamVo.getCheckoutDate())){
            mtHotelGoodsSpecParamVo.setCheckinDate(DateUtil.formatDate(new Date(),"yyyy-MM-dd"));
            mtHotelGoodsSpecParamVo.setCheckoutDate(DateUtil.formatDate(DateUtil.addDay(new Date(),30),"yyyy-MM-dd"));
        }

        Result<Object> apiResult = this.getMtHotelGoods(null,hotelList,mtHotelGoodsSpecParamVo.getCheckinDate(),mtHotelGoodsSpecParamVo.getCheckoutDate(),mtHotelGoodsSpecParamVo.getGoodsType());
        if(apiResult.getCode()==CommonConstants.SUCCESS){
            return new Result<>(apiResult.getData());
        }
        return apiResult;
    }

    /**
     * 请求获取酒店产品价格并保存
     *
     * 无论上送时间 只返回一个对象 显示有无库存
     * @param
     * @return
     */
    @Override
    public Result<Object> getMtHotelGoodsInventory(int goodsId, int roomId, String startDate, String endDate) {
        //业务参数
        String data = "";
        Map<String,Object> dataMap = new HashMap<>();
        dataMap.put("goodsId",goodsId);
        dataMap.put("roomId",roomId);
        dataMap.put("startDate",startDate);
        dataMap.put("endDate",endDate);
        data = JSON.toJSONString(dataMap);
        //发起请求
        String response = MtUtils.createParamsPost(data, MtHotelEnums.apiMethodEnum.METHOD_HOTEL_GOODS_INVENTORY.getMethod(),meituanSaveApiLogTask);
        //处理响应数据
        JSONObject responseJson = JSON.parseObject(response);
        if("0".equals(String.valueOf(responseJson.get("code")))) {
            String inventory = responseJson.getJSONObject("result").getString("goodsInventory");
            if (null != inventory) {
                MtHotelGoodsInventoryVo mtHotelGoodsInventoryVo = null;
                try {
                    mtHotelGoodsInventoryVo = JSON.parseObject(inventory, MtHotelGoodsInventoryVo.class);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (null == mtHotelGoodsInventoryVo) {
                    log.error("////////////////MTAPIERROR///////////////////酒店产品库存数据异常 mtHotelGoodsInventoryVo parse vo error");
                    return new Result<>("parse error", CommonConstants.PARSE_ERROR);
                }
                List<MtHotelGoodsInventory> list = new ArrayList<>();
                MtHotelGoodsInventory entity = new MtHotelGoodsInventory();
                String uniKey = String.valueOf(mtHotelGoodsInventoryVo.getRoomId())+String.valueOf(mtHotelGoodsInventoryVo.getGoodsId());
                entity.setUniKey(uniKey);
                entity.setId(String.valueOf(UUID.randomUUID()));
                entity.setMtHotelGoodsId(String.valueOf(mtHotelGoodsInventoryVo.getGoodsId()));
                entity.setMtHotelRoomId(String.valueOf(mtHotelGoodsInventoryVo.getRoomId()));
                entity.setMtStartDate(startDate);
                entity.setMtEndDate(endDate);
                entity.setMtRemain(mtHotelGoodsInventoryVo.getRemain()==null?0:mtHotelGoodsInventoryVo.getRemain());
                entity.setState(CommonEnums.STATE_NORMAL.getCode());
                entity.setRemark(response);
                entity.setCreateTime(DateUtil.getNowTime());
                entity.setModifyTime(DateUtil.getNowTime());
                list.add(entity);
                /*Map map = new HashMap();
                map.put("ids","'"+entity.getMtHotelGoodsId()+"'");
                int del = mtHotelGoodsInventoryMapper.deleteBatchByGoodsIds(map);
                if(del!=-1){
                    mtHotelGoodsInventoryMapper.insertList(list);
                }*/

                //判断有变动则保存日志,涉及库表数据对比，batchUpdateInsert放后面
                boolean checkInv = this.checkMtGoodsInventoryChange(entity);

                Integer upInser = mtHotelGoodsInventoryMapper.batchUpdateInsert(list);
                if(null != upInser && upInser <= 0){
                    log.error("////////////////MTAPIERROR///////////////////酒店产品库存 mtHotelGoodsInventoryMapper.batchUpdateInsert 更新插入异常 : {}",upInser);
                }

                if(checkInv){
                    return new Result<>(mtHotelGoodsInventoryVo,"invChange:"+JacksonUtil.objectToJson(entity));
                }else{
                    return new Result<>(mtHotelGoodsInventoryVo);
                }

            }else{
                log.error("////////////////MTAPIERROR///////////////////酒店产品库存接口数据异常 inventory is null");
                return new Result<>("inventory null", CommonConstants.REQUEST_ERROR);
            }
        }else{
            log.error("////////////////MTAPIERROR///////////////////酒店产品库存接口数据异常 {}",responseJson);
            return new Result<>(responseJson.getString("message"), CommonConstants.REQUEST_ERROR);
        }
    }
    /**
     * 上架天数：优势酒店：5天
     * @return
     */
    @Override
    public Integer getDaysCommonBaseSetForVip() {
        Integer returnDays;
        String daysCom = (String)redisService.get(CallbackConstants.SWMT_VIP_HOTELS_PRICE_STATUS_DAYS);
        if(ObjectUtils.isEmpty(daysCom)){
            Result result = RestTemplateUtils.get(CommonUrlConstants.ADMIN_HOST+"/sysCommonBase/value/"+CallbackConstants.SWMT_VIP_HOTELS_PRICE_STATUS_DAYS,null,restTemplate);
            if(result.getCode() == CommonConstants.SUCCESS && !ObjectUtils.isEmpty(result.getData())){
                daysCom = (String)result.getData();
                redisService.set(CallbackConstants.SWMT_VIP_HOTELS_PRICE_STATUS_DAYS,daysCom);
                returnDays = Integer.valueOf(daysCom);
            }else{
                SendUtils.dingMsgNotLog("callback getDaysCommonBaseSetForVip获取基础配置days异常请排查",DateUtil.getCurrTime()+" 当前设置默认值价格房态查询5天 result="+GsonUtils.GsonString(result), MessageEnums.genre.GOODS_STATUS_AND_PRICE.getCode(),restTemplate);
                returnDays = 5;//有异常默认5天并推送钉钉
            }
        }else{
            returnDays = Integer.valueOf(daysCom);
        }

        return returnDays;

    }

    /**
     * 酒店所有产品房态信息(根据酒店时间等查询)
     * 查询2020-05-20 到 2020-05-24
     * 返回多个产品每个产品三条数据，每个产品三条数据的依据是查询时间，2020-05-20 2020-05-21 2020-05-23
     * 包含起始时间，不包含结束时间
     * @param
     * @return
     */
    @Override
    public Result<Object> getMtHotelGoodsStatus(Long hotelId, String checkinDate, String checkoutDate, int goodstype,String source) {
        /*if(StringUtils.isEmpty(checkinDate)
                && StringUtils.isEmpty(checkoutDate)){
            checkinDate = DateUtil.formatDate(new Date(),"yyyy-MM-dd");
            checkoutDate = DateUtil.formatDate(DateUtil.addDay(new Date(),30),"yyyy-MM-dd");
        }*/
        //业务参数
        String data = "";
        Map<String,Object> dataMap = new HashMap<>();
        dataMap.put("hotelId",hotelId);
        dataMap.put("checkinDate",checkinDate);
        dataMap.put("checkoutDate",checkoutDate);
        dataMap.put("goodsType",goodstype);
        data = JSON.toJSONString(dataMap);
        //发起请求
        String response = MtUtils.createParamsPost(data, MtHotelEnums.apiMethodEnum.METHOD_HOTEL_GOODS_STATUS.getMethod(),meituanSaveApiLogTask);
        //处理响应数据
        JSONObject responseJson = JSON.parseObject(response);
        if("0".equals(String.valueOf(responseJson.get("code")))) {
            String result = responseJson.getString("result");
            if (!StringUtils.isEmpty(result)) {
                MtHotelGoodsStatusVo mtHotelGoodsStatusVo = null;
                try {
                    mtHotelGoodsStatusVo = JSON.parseObject(result, MtHotelGoodsStatusVo.class);
                } catch (Exception e) {
                    e.printStackTrace();
                }

                if (null == mtHotelGoodsStatusVo) {
                    log.error("////////////////MTAPIERROR///////////////////酒店产品价格接口数据异常 mtHotelGoodsInventoryVo parse vo error");
                    return new Result<>("parse error", CommonConstants.REQUEST_ERROR);
                }
                List<MtHotelGoodsStatusDetailVo> goodsList = mtHotelGoodsStatusVo.getGoodsStatuses();
                if(null != goodsList && goodsList.size()>0){

                    //保存日志
                    if(null == source){
                        //saveGoodsStatus(goodsList,String.valueOf(hotelId));
                    }
                    return new Result<>(mtHotelGoodsStatusVo);

                }else{
                    log.debug("////////////////MTAPIERROR///////////////////酒店产品状态接口数据异常 goodsList is nul:{}",responseJson);
                    return new Result<>(mtHotelGoodsStatusVo);
                }
            }else{
                log.debug("////////////////MTAPIERROR///////////////////酒店产品状态接口数据异常 result is nul",responseJson);
                return new Result<>("result null", CommonConstants.REQUEST_ERROR);
            }
        }else{
            log.error("////////////////MTAPIERROR///////////////////酒店产品状态接口数据异常 {}",responseJson);
            return new Result<>(responseJson.getString("message"), CommonConstants.REQUEST_ERROR);
        }
    }
    /**
     * 保存日志，trycatch内容不影响接口流程
     */
    @Override
    public void saveGoodsStatus(List<MtHotelGoodsStatusDetailVo> goodsList,String hotelId){
        List<MtHotelGoodsStatus> goodsEntityList = new ArrayList<>();
        for (MtHotelGoodsStatusDetailVo goods:goodsList){//遍历产品
            List<MtHotelGoodsStatusDetailStateVo> goodsStateDayList = goods.getGoodsStatuses();//某一产品多条某天状态数据
            for (MtHotelGoodsStatusDetailStateVo stateDayVo:goodsStateDayList){
                MtHotelGoodsStatus entity = new MtHotelGoodsStatus();
                String uniKey = hotelId+String.valueOf(goods.getGoodsId())+stateDayVo.getDate().replace("-","");
                entity.setUniKey(uniKey);
                entity.setId(String.valueOf(UUID.randomUUID()));
                entity.setMtHotelId(String.valueOf(hotelId));
                entity.setMtGoodsId(String.valueOf(goods.getGoodsId()));
                entity.setMtGoodsStatus(goods.getStatus());
                entity.setMtCheckDate(stateDayVo.getDate());
                entity.setMtCheckState(stateDayVo.getStatus());
                entity.setState(CommonEnums.STATE_NORMAL.getCode());
                entity.setRemark("");
                entity.setCreateTime(DateUtil.getNowTime());
                entity.setModifyTime(DateUtil.getNowTime());
                goodsEntityList.add(entity);
            }
        }
        try{
             /*//保存前执行删除已存在数据 根据条件  goodsId+checkDate
           int del = mtHotelGoodsStatusMapper.deleteByGoodsIdDay(goodsEntityList);
            if(del != -1){
                mtHotelGoodsStatusMapper.insertList(goodsEntityList);
            }*/
            Integer upInser = mtHotelGoodsStatusMapper.batchUpdateInsert(goodsEntityList);
            if(null != upInser && upInser <= 0){
                log.error("////////////////MTAPIERROR///////////////////酒店产品状态 mtHotelGoodsStatusMapper.saveGoodsStatus 更新插入异常 : {}",upInser);
            }else{
                //log.error("///////////////////////////////////酒店产品状态 mtHotelGoodsStatusMapper.saveGoodsStatus  upInser: {}",upInser);
            }

        }catch (Exception e){
            log.error("saveGoodsStatus 保存失败：goodsEntityList={},hotelId={}", JSON.toJSONString(goodsEntityList),hotelId);
            log.error(e.getMessage(),e);
        }
    }
    @Override
    public Result<Object> saveGetMtHotelGoodsPrice(Long goodsId, String startDate, String endDate) {
        List<Long> goodsIds = new ArrayList<>();
        goodsIds.add(goodsId);
        Result<Object> result= saveGetMtHotelGoodsPrice(null,goodsIds,startDate,endDate,null);
        if(result.getCode()==CommonConstants.SUCCESS){
            List<MtHotelGoodsPriceBaseVo> mtHotelGoodsPriceBaseVo = (List<MtHotelGoodsPriceBaseVo>)result.getData();
            if(null != mtHotelGoodsPriceBaseVo && mtHotelGoodsPriceBaseVo.size()>0){
                List<MtHotelGoodsPriceBaseDetailVo> priceModels = mtHotelGoodsPriceBaseVo.get(0).getPriceModels();
                return new Result<>(priceModels);
            }else{
                return new Result<>();
            }
        }else{
            return result;
        }
    }
    /**
     * 获取产品价格日历并保存数据库
     *
     * 获取2020-06-17的价格日历  需上送2020-06-17到2020-06-18  返回不包含20200618
     *
     * goodsIds	Array<Long>	否	[52786813]	需要查询价格日历的产品ID列表，每次最多查询的产品个数为10个。
     * hotelIds	Array<Long>	否	[182024891]	需要查询价格日历的酒店ID列表，每次最多查询的酒店个数为10个。
     * startDate	String	是	2017-09-01	价格日历开始时间（包含），格式为yyyy-MM-dd。
     * endDate	String	是	2017-09-10	价格日历结束时间（不包含），格式为yyyy-MM-dd。
     *
     *
     * @param hotelIds
     * @param goodsIds
     * @param startDate
     * @param endDate
     * @return
     */
    //接口文档地址:https://developer-distribution.meituan.com/distribution-open-platform/#/apiDocs/1/13/22
    @Override
    public Result<Object> saveGetMtHotelGoodsPrice(List<Long> hotelIds, List<Long> goodsIds, String startDate, String endDate,String source) {
        //上游要求：业务参数，hotelId和goodsId传其一，最好hotelId，个数支持最多10
        //上游：注意:hotelIds和goodsIds传一个即可，两个都传优先用hotelIds查询，建议使用hotelIds作为查询条件。
        //我们这边最好让下游都hotelId和goodsId都上送，，，上游有返回entity对应hotelId
        String data = "";
        Map<String, Object> dataMap = new HashMap<>();
        dataMap.put("hotelIds", hotelIds);
        dataMap.put("goodsIds", goodsIds);
        dataMap.put("startDate", startDate);
        dataMap.put("endDate", endDate);
        data = JSON.toJSONString(dataMap);
        //发起请求
        String response = MtUtils.createParamsPost(data, MtHotelEnums.apiMethodEnum.METHOD_HOTEL_GOODS_PRICE.getMethod(),meituanSaveApiLogTask);
        //处理响应数据
        JSONObject responseJson = JSON.parseObject(response);
        if ("0".equals(String.valueOf(responseJson.get("code")))) {
            String result = responseJson.getString("result");
            if (!StringUtils.isEmpty(result)) {
                MtHotelGoodsPriceVo mtHotelGoodsPriceVo = null;
                try {
                    mtHotelGoodsPriceVo = JSON.parseObject(result, MtHotelGoodsPriceVo.class);//转为响应对象
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (null == mtHotelGoodsPriceVo) {
                    log.error("////////////////MTAPIERROR///////////////////酒店产品价格接口数据异常 mtHotelGoodsPriceVo parse vo error:{}，，{}", responseJson, JSON.toJSONString(data));
                    return new Result<>("parse error", CommonConstants.REQUEST_ERROR);
                }
                List<MtHotelGoodsPriceBaseVo> mtHotelGoodsPriceBaseVoList = mtHotelGoodsPriceVo.getGoodsPrices();//获取出价格日历
                for (MtHotelGoodsPriceBaseVo base : mtHotelGoodsPriceBaseVoList) {//遍历价格日历
                    List<MtHotelGoodsPriceBaseDetailVo> priceList = base.getPriceModels();//获取产品信息集合
                    if (null != priceList && priceList.size() > 0) {
                        if(null != source && source.equals("saveGoodsPriceToCompareCreateSub")){
                            //saveGoodsPriceToCompareCreateSub();  不做保存价格日历
                        }else{
                            // saveGoodsPriceInfos(priceList,String.valueOf(base.getHotelId()),String.valueOf(base.getGoodsId()));
                        }
                    } else {
                        log.error("////////////////MTAPIERROR///////////////////酒店产品价格接口数据异常 goodsList is nul:{}，，{}", responseJson, JSON.toJSONString(data));
                    }
                }

                return new Result<>(mtHotelGoodsPriceBaseVoList);
            } else {
                log.error("////////////////MTAPIERROR///////////////////酒店产品价格接口数据异常 result is nul：{}，，{}", responseJson, JSON.toJSONString(data));
                return new Result<>("result null", CommonConstants.REQUEST_ERROR);
            }
        } else {
            log.error("////////////////MTAPIERROR///////////////////酒店产品价格接口数据异常：{}，，{}", responseJson, JSON.toJSONString(data));
            return new Result<>(responseJson.getString("message"), CommonConstants.REQUEST_ERROR);
        }
    }

    /**
     * 保存多组产品价格信息
     * @param priceListMap
     */
    @Override
    public void saveGoodsPriceInfosGroup(Map<String, List<MtHotelGoodsPriceBaseDetailVo>> priceListMap) {
        if(null != priceListMap && priceListMap.size()>0) {
            for (Map.Entry<String, List<MtHotelGoodsPriceBaseDetailVo>> entry : priceListMap.entrySet()) {
                List<MtHotelGoodsPriceBaseDetailVo> priceList = entry.getValue();
                String hotelId = entry.getKey().split(",")[0];
                String goodsId = entry.getKey().split(",")[1];
                saveGoodsPriceInfos(priceList,hotelId,goodsId);
            }
        }
    }

    /**
     * 保存一个产品的日期价格
     * @param priceList
     * @param hotelId
     * @param goodsId
     */
    @Override
    public void saveGoodsPriceInfos(List<MtHotelGoodsPriceBaseDetailVo> priceList,String hotelId,String goodsId){
        if(null != priceList && priceList.size()>0){
            List<MtHotelGoodsPrice> entityList = new ArrayList<>();
            for (int i = 0; i < priceList.size(); i++) {
                MtHotelGoodsPriceBaseDetailVo goods = priceList.get(i);
                MtHotelGoodsPrice entity = new MtHotelGoodsPrice();
                entity.setId(String.valueOf(UUID.randomUUID()));
                String uniKey = hotelId+goodsId+goods.getDate().replace("-","");
                entity.setUniKey(uniKey);
                entity.setMtHotelId(hotelId);
                entity.setMtSalePrice(goods.getSalePrice());
                entity.setMtGoodsId(goodsId);
                entity.setMtDate(goods.getDate());
                entity.setMtSubPrice(goods.getSubPrice());
                entity.setMtSubRatio(goods.getSubRatio());
                entity.setMtSettlePrice(goods.getSalePrice()-goods.getSubPrice());
                entity.setMtDayType(goods.getDayType());
                entity.setState(CommonEnums.STATE_NORMAL.getCode());
                entity.setRemark("");
                entity.setCreateTime(DateUtil.getNowTime());
                entity.setModifyTime(DateUtil.getNowTime());
                entityList.add(entity);

                //价格改变 更新美团产品相关表数据：增加产品价格变动日志 goods_price_change_log
                MtHotelGoodsPriceChangeLog mtHotelGoodsPriceChangeLog = new MtHotelGoodsPriceChangeLog();
                mtHotelGoodsPriceChangeLog.setId(StringUtil.getUUID());
                mtHotelGoodsPriceChangeLog.setMtHotelId(hotelId);
                mtHotelGoodsPriceChangeLog.setMtGoodsId(String.valueOf(goodsId));
                mtHotelGoodsPriceChangeLog.setMtDate(goods.getDate());
                mtHotelGoodsPriceChangeLog.setMtSalePrice(goods.getSalePrice());//最新价格
                mtHotelGoodsPriceChangeLog.setCreateTime(new Date());
                mtHotelGoodsPriceChangeLog.setSource(2);
                //mtHotelGoodsPriceChangeLog.setNowMtSalePrice(price);该字段调整为不保存，不再查出存在的上一个价格产品entity 减少数据库压力；根据库表里的数据就能看出上一次价格是多少
                try {
                    mtHotelGoodsPriceChangeLogMapper.insert(mtHotelGoodsPriceChangeLog);//酒店id+产品id+日期+价格 一般是不会重复，因为有变动的价格才会插入表
                }catch (Exception e){
                    e.printStackTrace();
                }

            }
            if(null != entityList && entityList.size()>0){
                Integer upInser = mtHotelGoodsPriceMapper.batchUpdateInsert(entityList);
                if(null != upInser && upInser <= 0){
                    log.error("////////////////MTAPIERROR///////////////////酒店产品价格 mtHotelGoodsInventoryMapper.batchUpdateInsert 更新插入异常 : {}",upInser);
                }else{
                    //log.error("///////////////////////////////////酒店产品库存 mtHotelGoodsInventoryMapper.batchUpdateInsert  upInser: {}",upInser);
                }
            }

        }
    }

    @Override
    public Result<Object> getCancelByGoodsInfo(String mtHotelId,String mtGoodsId,String checkinDate,String checkoutDate) {
        List<Long> ids = new ArrayList<>();
        List<MtHotelGoodsCancelRuleReturnVo> cList = new ArrayList<>();
        ids.add(Long.valueOf(mtHotelId));
        String mtDate = checkinDate;
        Long days = DateUtil.dateDiff(checkinDate,"day",checkoutDate,"yyyy-MM-dd");
        for (int i = 0; i < days; i++) {
            String nextDay = DateUtil.formatDate(DateUtil.addDay(mtDate,1),"yyyy-MM-dd");
            Result result = getMtHotelGoods(null,ids,mtDate,nextDay,MtGoodsEnums.roomDateTypeEnum.DAY.getCode());
            if(result.getCode()==CommonConstants.SUCCESS && null != result.getData()){
                MtHotelGoodsVo mtHotelGoodsVo = (MtHotelGoodsVo)result.getData();
                if(null != mtHotelGoodsVo){
                    List<MtHotelGoodsChildInfoVo> hotelGoods = mtHotelGoodsVo.getHotelGoods();
                    if(null != hotelGoods && hotelGoods.size()>0 && null != hotelGoods.get(0).getGoods() && hotelGoods.get(0).getGoods().size()>0){
                        for (MtHotelGoodsBaseInfoVo one:hotelGoods.get(0).getGoods()){
                            String thisGoodsId = one.getGoodsId();
                            if(thisGoodsId.equals(mtGoodsId)){
                                List<MtHotelGoodsCancelRuleVo> cancelRules = one.getCancelRules();
                                if(null != cancelRules && cancelRules.size()>0){
                                    MtHotelGoodsCancelRuleVo oneDateCancel = cancelRules.get(0);
                                    MtHotelGoodsCancelRuleReturnVo mtHotelGoodsCancelRuleReturnVo = new MtHotelGoodsCancelRuleReturnVo();
                                    BeanCopierUtil.copy(oneDateCancel,mtHotelGoodsCancelRuleReturnVo);
                                    mtHotelGoodsCancelRuleReturnVo.setDate(mtDate);
                                    cList.add(mtHotelGoodsCancelRuleReturnVo);
                                    break;
                                }
                                break;
                            }

                        }
                    }

                }
            }
            mtDate = nextDay;
        }
        return new Result<>(GsonUtils.GsonString(cList),"success");
    }

    @Override
    public Result<Object> checkGoodsCancel(String mtHotelId,String mtGoodsId,String checkinDateYmd) {
        //查询库表根据产品信息获取取消规则

        //version  20200814   调整为每次判断是否取消就先调用查询产品规则信息接口，得到最实时的取消信息
        List<Long> ids = new ArrayList<>();
        ids.add(Long.valueOf(mtHotelId));
        String tempCheckoutDate = DateUtil.formatDate(DateUtil.addDay(checkinDateYmd,1),"yyyy-MM-dd"); //获取入住日是否可取消 该入住日往后加一天进行查询
        Result result = getMtHotelGoods(null,ids,checkinDateYmd,tempCheckoutDate,MtGoodsEnums.roomDateTypeEnum.DAY.getCode());
        if(result.getCode()!=CommonConstants.SUCCESS && null != result.getData()){
            log.error("checkGoodsCancel 产品获取异常：{},{}", JSON.toJSONString(result));//获取接口异常也要调用findDataGoodsCancelRuleByGoodsIdOneDay 查表
            Result isCancelCode = findDataGoodsCancelRuleByGoodsIdOneDay(mtHotelId,mtGoodsId,checkinDateYmd);
            //if(isCancelCode.getCode()!=CommonConstants.SUCCESS){
            ////数据库没有数据，调用接口后再次查询数据库
            //}else{
            //return isCancelCode;
            //}
            return isCancelCode;
        }else{
            //接口成功保存数据
            /*Result<Object> save = saveGoodsData(null,(MtHotelGoodsVo)result.getData());
            if(null != save && save.getCode()==CommonConstants.SUCCESS){
            }else{
                log.error("checkGoodsCancel 产品获取后保存致数据库异常 saveGoodsData：{},{}",JSON.toJSONString(save));
                return new Result<>(false);
            }*/
            //校验时间
            Result isCancelCodeAgain =  findDataGoodsCancelRuleByGoodsIdOneDay(mtHotelId,mtGoodsId,checkinDateYmd);
            return isCancelCodeAgain;
        }

        /*Integer isCancelCode = findDataGoodsCancelRuleByGoodsIdOneDay(mtHotelId,mtGoodsId,checkinDateYmd);
        if(1 == isCancelCode){//可取消
            return new Result<>(true);
        }else if(0==isCancelCode){//数据库没有数据，调用接口后再次查询数据库
            List<Long> ids = new ArrayList<>();
            ids.add(Long.valueOf(mtHotelId));
            String tempCheckoutDate = DateUtil.formatDate(DateUtil.addDay(checkinDateYmd,1),"yyyy-MM-dd"); //获取入住日是否可取消 该入住日往后加一天进行查询
            Result result = getMtHotelGoods(null,ids,checkinDateYmd,tempCheckoutDate,MtGoodsEnums.roomDateTypeEnum.DAY.getCode());
            if(result.getCode()!=CommonConstants.SUCCESS && null != result.getData()){
                log.error("checkGoodsCancel 产品获取异常：{},{}",JSON.toJSONString(result));
            }
            Result<Object> save = saveGoodsData(null,(MtHotelGoodsVo)result.getData());
            if(null != save && save.getCode()==CommonConstants.SUCCESS){
                Integer isCancelCodeAgain =  findDataGoodsCancelRuleByGoodsIdOneDay(mtHotelId,mtGoodsId,checkinDateYmd);
                if(1 == isCancelCodeAgain){
                    return new Result<>(true);
                }else{
                    return new Result<>(false);
                }
            }else{
                log.error("checkGoodsCancel 产品获取后保存致数据库异常 saveGoodsData：{},{}",JSON.toJSONString(save));
                return new Result<>(false);
            }
        }else{//不可取消
            return new Result<>(false);
        }*/
    }

    public Result findDataGoodsCancelRuleByGoodsIdOneDay(String mtHotelId,String mtGoodsId,String checkinDateYmd){
        log.info("检验是否可取消 findDataGoodsCancelRuleByGoodsIdOneDay ：{},{},{}",mtHotelId,mtGoodsId,checkinDateYmd);

        String nowYmd = DateUtil.formatDate(DateUtil.getNowTime(),"yyyy-MM-dd");// HH:mm:ss
        String nowYmdHHmmss = DateUtil.formatDate(DateUtil.getNowTime(),"yyyy-MM-dd HH:mm:ss");// HH:mm:ss

        Example example = new Example(MtHotelGoodsCancelRule.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andCondition("mt_hotel_id=", mtHotelId);
        criteria.andCondition("mt_goods_id=", mtGoodsId);
        //criteria.andCondition("DATE_FORMAT(create_time,'%Y-%m-%d') =", checkinDateYmd);
        List<MtHotelGoodsCancelRule> cancelRules = mtHotelGoodsCancelRuleMapper.selectByExample(example);
        if(null != cancelRules && cancelRules.size()>0){
            MtHotelGoodsCancelRule mtHotelGoodsCancelRule = cancelRules.get(0);
            if(mtHotelGoodsCancelRule.getMtCancelType()==1){
                Integer aheadDays = mtHotelGoodsCancelRule.getMtAheadCancelDays();
                if(aheadDays==0){//0 表示入住日可取消，入住时间等于今天，则需判断具体时间段 nowYmdHHmmss
                    if(checkinDateYmd.equals(nowYmd)){
                        return compareNowdayCancel(nowYmd+" "+mtHotelGoodsCancelRule.getMtAheadCancelHours(),nowYmdHHmmss,mtHotelGoodsCancelRule,mtHotelId,mtGoodsId);
                    }else{
                        //return 1;//可取消
                        return  new Result<>(true,"可取消");
                    }
                }else{
                    //大于0  表示要入住日前提前n天进行取消,如=3，则提前三天；；则需要截止时间和今日下单时间进行比较；
                    Date dealineTimeYmd = DateUtil.addDay(checkinDateYmd,-aheadDays);
                    String dealineTimeYmdStr = DateUtil.formatDate(dealineTimeYmd,"yyyy-MM-dd");
                    int dif = DateUtil.compareDate(dealineTimeYmdStr,nowYmd,"yyyy-MM-dd");
                    if(dif<0) {//-1 小于 0 等于  1 大于
                        //截止时间小于当前下单时间，当前下单时间超过了最晚取消时间，则不可取消了，返回-1；
                        log.info(" 需提前{}天可取消，截止时间小于当前下单时间，当前下单时间超过了最晚取消时间，" +
                                        "今日不可取消 返回 ：checkinDateYmd={}，mtHotelId={},mtGoodsId={},dealineTimeYmd={},mtHotelGoodsCancelRule={}"
                                ,aheadDays,checkinDateYmd,mtHotelId,mtGoodsId,dealineTimeYmdStr, JSON.toJSONString(mtHotelGoodsCancelRule));
                        //return -1;
                        return  new Result<>(false,"需提前"+aheadDays+"天可取消，截止时间小于当前下单时间，当前下单时间超过了最晚取消时间，今日不可取消");
                    }else if(dif==0) {
                        //截止时间等于下单时间，同一天需要比较具体时间段 nowYmdHHmmss
                        return compareNowdayCancel(dealineTimeYmdStr+" "+mtHotelGoodsCancelRule.getMtAheadCancelHours(),nowYmdHHmmss,mtHotelGoodsCancelRule,mtHotelId,mtGoodsId);
                    }else{
                        //可取消 截止时间大于当前下单时间
                        //return 1;
                        return  new Result<>(true,"可取消 截止时间大于当前下单时间");
                    }
                }
            }else{
                //产品取消规则就是不可取消
                log.info(" 美团检验是否可取消，checkGoodsCancel 该产品默认规则为不可取消：{}", JSON.toJSONString(mtHotelGoodsCancelRule));
                //return -1;
                return  new Result<>(false,"该产品默认规则为不可取消");
            }
        }else{
            log.info("数据库未找到去取消规则数据");
            //return 0;//再次调用接口保存数据 返回CommonConstants.REQUEST_ERROR
            return  new Result<>(false,CommonConstants.REQUEST_ERROR);
        }
    }

  /*  public static void main(String[] args) {

        String nowYmd = DateUtil.formatDate(DateUtil.getNowTime(),"yyyy-MM-dd");
        int dif = DateUtil.compareDate("2020-08-17",nowYmd,"yyyy-MM-dd");
        System.out.printf(""+dif);
    }*/

    /**
     * 返回result  true或false  取消或不可取消
     * @param dealineTimeYmdHms
     * @param compareDateYmdHms
     * @param mtHotelGoodsCancelRule
     * @param mtHotelId
     * @param mtGoodsId
     * @return
     */
    public Result compareNowdayCancel(String dealineTimeYmdHms,String compareDateYmdHms,MtHotelGoodsCancelRule mtHotelGoodsCancelRule,String mtHotelId,String mtGoodsId){
        log.info("aheadDays=0且截止时间等于入住时间  或   aheadDays大于0提前取消截止时间等于当前下单时间 ，需进行具体时间段比较  compareNowdayCancel dealineTimeYmdHms={},,compareDateYmdHms={}",dealineTimeYmdHms,compareDateYmdHms);

        //截止时间大于当前时间
        //判断距离今日截止时间前20分钟都要返回false 让单子为延时单
        Long difMin = DateUtil.dateDiff(compareDateYmdHms,"min",dealineTimeYmdHms,"yyyy-MM-dd HH:mm:ss");//dateDiff  当前时间放在startTime，截止时间放在endTime；大于0则 当前时间大于截止时间
        log.info("aheadDays=0且截止时间等于入住时间  或   aheadDays大于0提前取消截止时间等于当前下单时间 ，需进行具体时间段比较  compareNowdayCancel difMin={}",difMin);
        if(difMin>=20){
            log.info(" compareNowdayCancel，可取消， 当前时间大于截止时间20分钟可取消 ：{},{}，{}，{},{}",String.valueOf(difMin),dealineTimeYmdHms,compareDateYmdHms,mtHotelId,mtGoodsId, JSON.toJSONString(mtHotelGoodsCancelRule));
            //return 1;
            return new Result<>(true,"可取消， 当前时间大于截止时间20分钟可取消");
        }else{
            log.info(" compareNowdayCancel，不可取消， 当前时间大于截止时间不够20分钟不可取消 ：{},{}，{}，{},{}",String.valueOf(difMin),dealineTimeYmdHms,compareDateYmdHms,mtHotelId,mtGoodsId, JSON.toJSONString(mtHotelGoodsCancelRule));
            //return -1;
            return new Result<>(false,"不可取消， 当前时间大于截止时间不够20分钟不可取消");
        }
    }

    /**
     * 获取产品价格日历不上送酒店id，定时器需要该操作
     *
     * 时间默认上送 开始时间 几天，结束时间明天
     *
     *
     * @param goodsIds
     * @param startDate
     * @param endDate
     * @return
     */
    @Override
    public Result<Object> getMtHotelGoodsPriceNotSave(List<Long> hotelIds, List<Long> goodsIds, String startDate, String endDate) {
        //上游要求：业务参数，hotelId和goodsId传其一，最好hotelId，个数支持最多10
        //上游：注意:hotelIds和goodsIds传一个即可，两个都传优先用hotelIds查询，建议使用hotelIds作为查询条件。
        String data = "";
        Map<String, Object> dataMap = new HashMap<>();
        dataMap.put("hotelIds", hotelIds);
        dataMap.put("goodsIds", goodsIds);
        dataMap.put("startDate", startDate);
        dataMap.put("endDate", endDate);
        data = JSON.toJSONString(dataMap);
        //发起请求
        String response = MtUtils.createParamsPost(data, MtHotelEnums.apiMethodEnum.METHOD_HOTEL_GOODS_PRICE.getMethod(),meituanSaveApiLogTask);
        //处理响应数据
        JSONObject responseJson = JSON.parseObject(response);
        if ("0".equals(String.valueOf(responseJson.get("code")))) {
            String result = responseJson.getString("result");
            if (!StringUtils.isEmpty(result)) {
                MtHotelGoodsPriceVo mtHotelGoodsPriceVo = null;
                try {
                    mtHotelGoodsPriceVo = JSON.parseObject(result, MtHotelGoodsPriceVo.class);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (null == mtHotelGoodsPriceVo) {
                    log.error("////////////////MTAPIERROR///////////////////酒店产品价格接口数据异常 mtHotelGoodsPriceVo parse vo error:{}，，{}", responseJson, JSON.toJSONString(data));
                    return new Result<>("parse error", CommonConstants.REQUEST_ERROR);
                }
                List<MtHotelGoodsPriceBaseVo> mtHotelGoodsPriceBaseVo = mtHotelGoodsPriceVo.getGoodsPrices();
                for (MtHotelGoodsPriceBaseVo base : mtHotelGoodsPriceBaseVo) {
                    List<MtHotelGoodsPriceBaseDetailVo> priceList = base.getPriceModels();
                    if (null != priceList && priceList.size() > 0) {
                        //saveGoodsPriceInfos(priceList,String.valueOf(base.getHotelId()),String.valueOf(base.getGoodsId()));
                        //该方法特殊处理，不做保存更新操作，在外边业务结束后再进行更新价格主表操作
                    } else {
                        log.error("////////////////MTAPIERROR///////////////////酒店产品价格接口数据异常 goodsList is nul:{}，，{}", responseJson, JSON.toJSONString(data));
                    }
                }
                return new Result<>(mtHotelGoodsPriceBaseVo);
            } else {
                log.error("////////////////MTAPIERROR///////////////////酒店产品价格接口数据异常 result is nul：{}，，{}", responseJson, JSON.toJSONString(data));
                return new Result<>("result null", CommonConstants.REQUEST_ERROR);
            }
        } else {
            log.error("////////////////MTAPIERROR///////////////////酒店产品价格接口数据异常：{}，，{}", responseJson, JSON.toJSONString(data));
            return new Result<>(responseJson.getString("message"), CommonConstants.REQUEST_ERROR);
        }
    }


    public Boolean checkMtGoodsInventoryChange(MtHotelGoodsInventory entity) {
        log.info(" 库存，checkMtGoodsInventoryChange ,进入方法：{}", JSON.toJSONString(entity));
        MtHotelGoodsInventory queryEntity = new MtHotelGoodsInventory();
        queryEntity.setMtHotelGoodsId(entity.getMtHotelGoodsId());
        queryEntity.setMtHotelRoomId(entity.getMtHotelRoomId());
        //queryEntity.setMtStartDate(entity.getMtStartDate());
        //queryEntity.setMtEndDate(entity.getMtEndDate());
        queryEntity.setMtRemain(entity.getMtRemain());//库存 0 或 1  有变动才保存日志
        List<MtHotelGoodsInventory> p = mtHotelGoodsInventoryMapper.select(queryEntity);//该表中一条数据一个商品
        if(null == p || p.size() ==0){//存中变动库存才保存日志
            log.info(" 库存变化 ， checkMtGoodsInventoryChange ,null == p || p.size() ==0");
            queryEntity.setMtRemain(null);
            List<MtHotelGoodsInventory> exisGoods = mtHotelGoodsInventoryMapper.select(queryEntity);
            if(null != exisGoods){//已存在该商品库存记录，有跟该记录进行对比
                MtHotelGoodsInventoryLog mtHotelGoodsInventoryLog = new MtHotelGoodsInventoryLog();
                BeanUtils.copyProperties(entity,mtHotelGoodsInventoryLog);
                mtHotelGoodsInventoryLog.setCreateTime(new Date());
                mtHotelGoodsInventoryLog.setModifyTime(mtHotelGoodsInventoryLog.getCreateTime());
                log.info(" 库存变化 null != exisGoods， checkMtGoodsInventoryChange ,mtHotelGoodsInventoryLog：{}", JSON.toJSONString(mtHotelGoodsInventoryLog));
                mtHotelGoodsInventoryLogMapper.insert(mtHotelGoodsInventoryLog);
                return true;
            }
        }
        return false;
    }

    /**
     * 根据房型id获取该房型底下所有产品
     * @param roomId
     * @return
     */
    @Override
    public Result<List<MtHotelGoodsDto>> getMtGoodsByRoomId(String mtHotelId,String roomId) {
        List<MtHotelGoodsDto> mtHotelGoodsDtosMap=new ArrayList<>();

        //物理房型信息
        MtHotelRoom mtHotelRoom=new MtHotelRoom();
        mtHotelRoom.setMtHotelId(mtHotelId);
        mtHotelRoom.setMtRoomId(roomId);///接口中的realRoomId 真实的物理房型id
        List<MtHotelRoom> room = mtHotelRoomMapper.select(mtHotelRoom);
        if(null == room || room.size()==0){
            //没有查询到物理房型信息
            return new Result<>(mtHotelGoodsDtosMap,"物理房型信息为空请核实roomId");
        }
        MtHotelRoom existBasicRoom = room.get(0);
        String basicRoomName = existBasicRoom.getMtRoomName();//物理房型名称

        //产品列表
        MtHotelGoods mtHotelGood=new MtHotelGoods();
        Example example = new Example(MtHotelGoods.class);
        mtHotelGood.setMtRoomId(roomId);
        example.createCriteria()
                .andCondition("mt_hotel_id = ",String.valueOf(mtHotelId))
                .andCondition("mt_room_id = ",String.valueOf(roomId))
                .andCondition("mt_goods_status = 1")//可预订
                .andCondition("mt_goods_type = 1");//全日房
        List<MtHotelGoods> mtHotelGoods=mtHotelGoodsMapper.selectByExample(example);
        if(null == mtHotelGoods && mtHotelGoods.size()==0){
            return new Result<>(mtHotelGoodsDtosMap,"该物理房型下无产品信息："+roomId);
        }

        for (MtHotelGoods thisGoods:mtHotelGoods){
            String thisGoodsId = thisGoods.getMtGoodsId();
            //早餐
            MtHotelGoodsBreakfast mtHotelGoodsBreakfast=new MtHotelGoodsBreakfast();
            mtHotelGoodsBreakfast.setMtGoodsId(thisGoodsId);
            List<MtHotelGoodsBreakfast> breakfastEntityList = mtHotelGoodsBreakfastMapper.select(mtHotelGoodsBreakfast);
            //预定规则
            MtHotelGoodsBookRule mtHotelGoodsBookRule=new MtHotelGoodsBookRule();
            mtHotelGoodsBookRule.setMtGoodsId(thisGoodsId);
            List<MtHotelGoodsBookRule> bookRuleEntityList = mtHotelGoodsBookRuleMapper.select(mtHotelGoodsBookRule);
            //取消规则
            MtHotelGoodsCancelRule mtHotelGoodsCancelRule=new MtHotelGoodsCancelRule();
            mtHotelGoodsCancelRule.setMtGoodsId(thisGoodsId);
            List<MtHotelGoodsCancelRule> cancelRuleEntityList = mtHotelGoodsCancelRuleMapper.select(mtHotelGoodsCancelRule);

            MtHotelGoodsDto mtHotelGoodsDto=new MtHotelGoodsDto();
            BeanUtils.copyProperties(thisGoods,mtHotelGoodsDto);

            List<MtHotelGoodsBreakfastDto> breakfastDtoList=new ArrayList<>();
            List<MtHotelGoodsCancelRuleDto> cancelRuleDtoList=new ArrayList<>();
            List<MtHotelGoodsBookRuleDto> bookRuleDtoList=new ArrayList<>();
            BeanUtils.copyProperties(breakfastEntityList,breakfastDtoList);
            BeanUtils.copyProperties(bookRuleEntityList,bookRuleDtoList);
            BeanUtils.copyProperties(cancelRuleEntityList,cancelRuleDtoList);
            mtHotelGoodsDto.setBookRuleList(bookRuleDtoList);
            mtHotelGoodsDto.setBreakfastList(breakfastDtoList);
            mtHotelGoodsDto.setCancelRuleList(cancelRuleDtoList);
            mtHotelGoodsDtosMap.add(mtHotelGoodsDto);
        }

        return new Result<>(mtHotelGoodsDtosMap);
    }

    @Override
    public Result<Object> getMtInventoryByGoodsIdAndRoomId(Integer goodsId, Integer roomId) {
        Example example = new Example(MtHotelGoodsCancelRule.class);
        example.createCriteria().andCondition("mt_hotel_goods_id=", goodsId);
        example.createCriteria().andCondition("mt_hotel_room_id=", roomId);
        List<MtHotelGoodsInventory> entity = mtHotelGoodsInventoryMapper.selectByExample(example);
        if(null != entity && entity.size()>0){
            MtHotelGoodsInventoryVo mtHotelGoodsInventoryVo = new MtHotelGoodsInventoryVo();
            mtHotelGoodsInventoryVo.setGoodsId(goodsId);
            mtHotelGoodsInventoryVo.setRoomId(roomId);
            mtHotelGoodsInventoryVo.setRemain(entity.get(0).getMtRemain());
            return new Result<>(mtHotelGoodsInventoryVo);
        }
        return new Result<>();
    }


}
